本帖最后由 追逐 于 2014-4-5 18:58 编辑
- import java.io.InputStream;
- import java.io.OutputStream;
- import java.net.ServerSocket;
- import java.net.Socket;
- class TcpClient1
- {
- public static void main(String[] args) throws Exception
- {
- Socket s = new Socket("13.206.242.133", 10005);
- OutputStream os = s.getOutputStream();
- os.write("哥们我来了".getBytes());
-
- InputStream is = s.getInputStream();
- byte[] by = new byte[1024];
- int len = is.read(by);
- System.out.println(new String(by, 0, len));
- s.close();
- }
- }
- class TcpServer1
- {
- public static void main(String[] args) throws Exception
- {
- ServerSocket ss = new ServerSocket(10005);
- Socket s = ss.accept();
- String ip = s.getInetAddress().getHostAddress();
- System.out.println(ip);
- InputStream is = s.getInputStream();
- byte[] by = new byte[1024];
- int len = is.read(by);
- System.out.println(new String(by, 0, len));
- OutputStream os = s.getOutputStream();
- os.write("哥们收到:你也好".getBytes());
- ss.close();
- s.close();
- }
- }
复制代码 运行后的结果和视频中的结果不一样为什么呢?
下面有个我的程序运行后出现的结果。为什么会这样呢。求大神帮忙解答一下
|
|