没报错啊
import
import
import
import
public class ServerDemo {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(8888);
Socket s = ss.accept();
String ip = s.getInetAddress().getHostAddress();
InputStream is = s.getInputStream();
byte[] buf = new byte[1024];
/*int len = is.read(buf);
String message = new String(buf,0,len);*/
String message = new String(buf,0,is.read(buf));
System.out.println("客户端为:"+ip+" 的 发来信息:
"+message);
}
}
import
import
import
import
public class ClientDemo {
public static void main(String[] args) throws UnknownHostException, IOException{
Socket client=new Socket("192.168.1.101",8888);
OutputStream out=client.getOutputStream();
byte[] b="hello".getBytes();
out.write(b, 0, b.length);
out.close();
client.close();
}
}