1、把服务器的数据写到客户端 用 socket.getOutputStream()。
开启telnet作为客户端。
public class ChatService { public static void main(String[] args) throws Exception { new ChatService().start(); } private void start() throws Exception { ServerSocket server=new ServerSocket(8090); while(true){ Socket socket=server.accept(); OutputStream out=socket.getOutputStream(); String s="hello client"; byte [] data=s.getBytes(); out.write(data); out.flush(); out.close(); } } }
2、怎样将客户端的数据传到服务器:
用socket.getInputSream();