scoket4.java
来自「java网络编程」· Java 代码 · 共 46 行
JAVA
46 行
package scoket;
/*第3题*/
import java.net.*;
import java.io.*;
public class Scoket4 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Socket thesocket=null;
while(true)
{
try{
String host="localhost";
String s;
thesocket=new Socket(host,2306);
System.out.print("客户端的IP是"+thesocket.getInetAddress()+"端口是"+thesocket.getLocalPort()+"\n");
System.out.print("接到服务器发的数据\n");
BufferedReader buffer =new BufferedReader(new InputStreamReader(thesocket.getInputStream()));
System.out.print(buffer.readLine());
while(( s=buffer.readLine())!=null)
{
System.out.print(s);
}
}
catch(Exception e)
{
e.printStackTrace();
}
finally{
try{
thesocket.close();
}
catch(IOException er)
{
er.printStackTrace();
}
}
try{
Thread.sleep(1000);
}
catch(Exception e)
{e.printStackTrace();}
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?