import java.net.*;
import java.io.*;
public class TClient{
public static void main(String [] args)throws Exception{
Socket s=new Socket("192.168.1.100",10002);
OutputStream out=s.getOutputStream();
DataOutputStream write=new DataOutputStream(out);
write.writeUTF("nihao");
write.flush();
write.close();
s.close();
}
}
-----------------------------------------------
import java.net.*;
import java.io.*;
public class TServer{
public static void main(String[]agrs ) throws Exception{
ServerSocket ss =new ServerSocket(10002);
while(true){
Socket s=ss.accept();
System.out.print("linted");
DataInputStream read=new DataInputStream(s.getInputStream());
System.out.print(read.readUTF());
read.close();
s.close();
}
}
}
为什么write调用flush()而read没有调用,还有就是OutputStram在这里为什么不需要close?
|