- import java.net.*;
- import java.io.*;
- class TcpClient
- {
- public static void main(String[] args) throws Exception
- {
- Socket s = new Socket("192.186.1.108",10003);
- OutputStream out = s.getOutputStream();
-
- out.write("hello the world!".getBytes());
- s.close();
- }
- }
- class TcpServer
- {
- public static void main(String[] args)throws Exception
- {
- ServerSocket ss = new ServerSocket(10003);
- Socket s = ss.accept();
- String ip = s.getInetAddress().getHostAddress();
- System.out.println(ip+".....已连接");
- InputStream in = s.getInputStream();
- byte[] buf = new byte[1024];
-
- int len = in.read(buf);
- System.out.println(new String(buf,0,len));
- s.close();
- }
- }
复制代码 看看我的陈雪有什么问题,为什么在客户端和服务端都么有反应? |