?? scoket4.java
字號:
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 + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -