import java.io.*;
import java.net.*;
class TcpClient2
{
public static void main(String[] args)throws Exception
{
Socket s = new Socket("192.168.1.254",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();
}
}
class TcpServer2
{
public static void main(String[] args) throws Exception
{
ServerSocket ss = new ServerSocket(10004);
Socket s = ss.accept();
String ip = s.getInetAddress().getHostAddress();
System.out.println(ip+"....connected");
InputStream in = s.getInputStream();
byte[] buf = new byte[1024];
int len = in.read(buf);
System.out.println(new String(buf,0,len));
OutputStream out = s.getOutputStream();
Thread.sleep(10000);
out.write("你也好".getBytes());
s.close();
ss.close();
}
}视频讲解上说 用阻塞式方法,流之间传输不会冲突,是什么含义呀?
而且我感觉此题 输入流,输出流之间的流向很混乱?请大家帮忙解释一下!! |