openmv代码,SSID和KEY需要修改成可以连接的wifi
# Connect Example
#
# This example shows how to connect your OpenMV Cam with a WiFi shield to the net.
import network,usocket, sys, json,socket
SSID='ymc' # Network SSID
KEY='44661122' # Network key
HOST = '192.168.191.2' # Use first available interface #192.168.199.220
PORT = 12345 # Arbitrary non-privileged port
# Init wlan module and connect to network
print("Trying to connect... (may take a while)...")
wlan = network.WINC()
wlan.connect(SSID, key=KEY, security=wlan.WPA_PSK)
# We should have a valid IP now via DHCP
print(wlan.ifconfig())
s = usocket.socket(usocket.AF_INET, usocket.SOCK_STREAM)
s.connect([HOST, PORT])
#s.send("this is from car1")
try:
#一个个读数据试试
data = s.recv(100)
print ("data is:",str(data))
s.close()
except OSError as e:
s.close()
print("socket error: ", e)
java代码
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class SocketTest {
public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(12345);
Socket socket = serverSocket.accept();
OutputStream outputStream = socket.getOutputStream();
outputStream.write("aaasdfsdfdsf".getBytes());
} catch (IOException e) {
e.printStackTrace();
}
}
}
结果
麻烦你了。