如何使用Java中的Socket通过客户端向服务器发送两个字符串?

时间:2014-08-09 05:45:27

标签: java sockets

这里是我的代码(只发送一个字符串)

客户端

Socket sock = new Socket("localhost",9999);    
Scanner in = new Scanner(System.in);
String msg;

PrintStream pr = new PrintStream(sock.getOutputStream());

System.out.print("Enter the Msg : ");
msg = in.nextLine();

pr.print(msg);

服务器

ServerSocket ser = new ServerSocket(9999);
Socket sock = ser.accept();

BufferedReader br = new BufferedReader(new InputStreamReader(sock.getInputStream()));

String msg = br.readLine();

System.out.println("Received Msg : "+msg);

此代码清楚地起作用。但我想通过客户端向服务器发送两个字符串。

0 个答案:

没有答案