📄 client2.java
字号:
package socket.test.tcp;/** * <p>Title: </p> * <p>Description: </p> * <p>Copyright: Copyright (c) 2005</p> * <p>Company: </p> * @author not attributable * @version 1.0 */import java.io.*;import java.net.*;public class Client2{ public static void main(String args[]) { String s=null; Socket mysocket; DataInputStream in=null; DataOutputStream out=null; try{ mysocket=new Socket("localhost",4331); in=new DataInputStream(mysocket.getInputStream()); out=new DataOutputStream(mysocket.getOutputStream()); out.writeUTF("你好!");//通过 out向"线路"写入信息。 while(true) { s=in.readUTF();//通过使用in读取服务器放入"线路"里的信息。堵塞状态, //除非读取到信息。 out.writeUTF(":"+Math.random()); System.out.println("客户收到:"+s); Thread.sleep(3000); } } catch(IOException e) { System.out.println("无法连接"); } catch(InterruptedException e){} }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -