标签:except body puts cep net auto str code 服务端
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
package socket; import java.io.DataOutputStream; import java.io.IOException; import java.io.OutputStream; import java.net.Socket; import java.net.UnknownHostException; import java.util.Scanner; public class Client { public static void main(String[] args) { try { Socket s = new Socket( "127.0.0.1" , 8888 ); OutputStream os = s.getOutputStream(); DataOutputStream dos = new DataOutputStream(os); //使用Scanner读取控制台的输入,并发送到服务端 Scanner sc = new Scanner(System.in); String str = sc.next(); dos.writeUTF(str); dos.close(); s.close(); } catch (UnknownHostException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } |
标签:except body puts cep net auto str code 服务端
原文地址:https://www.cnblogs.com/chinaifae/p/10194872.html