class TCPClient2 implements Runnable{
@Override
public void run() {
try {
Socket s = new Socket("192.168.1.101",10004);
OutputStream out = s.getOutputStream();
out.write("服务端,你好".getBytes());
InputStream in = s.getInputStream();
byte[] buf = new byte[1024];
int len = in.read(buf);
System.out.println(new String(buf,0,len));
s.close();
} catch (Exception e) {
}
}
}
class TCPServer2 implements Runnable{
@Override
public void run() {
try {
ServerSocket ss = new ServerSocket(10004);
Socket s = ss.accept();
String ip = s.getInetAddress().getHostAddress();
System.out.println(ip+"....connected");
InputStream is = s.getInputStream();
byte[] buf = new byte[1024];
int len = is.read();
System.err.println(new String(buf,0,len));
OutputStream os = s.getOutputStream();
os.write("哥们收到,你好".getBytes());
s.close();
ss.close();
} catch (Exception e) {
}
}
}
public class TCPDemo2 {
public static void main(String[] args) {
new Thread(new TCPClient2()).start();
new Thread(new TCPServer2()).start();
}
}
这是我整个程序,运行结果是:
192.168.1.101....connected
[][][][][][][][][][][][][][][][][][]
哥们收到,你好
怎么客户端的信息没显示呢,谁能看明白吗? |