?? client.java
字號:
/*
* Created on 2004-8-11
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package socket_communicate;
import java.io.*;
import java.net.*;
/**
* @author Administrator
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class Client {
public Client(String hostname,int port)
{
try
{
Socket clientsocket=new Socket(hostname,port);
PrintWriter out=new PrintWriter(clientsocket.getOutputStream(),true);
BufferedReader in=new BufferedReader(new InputStreamReader(clientsocket.getInputStream()));
BufferedReader user_in=new BufferedReader(new InputStreamReader(System.in));
String line_user;
String line_server;
while((line_user=user_in.readLine())!=null)
{
if(line_user.equals("88"))//斷開連接的輸入
break;
out.println(line_user);
line_server=in.readLine();
System.out.println("Client receive:"+line_server);
}
out.close();
in.close();
clientsocket.close();
}
catch (UnknownHostException e)
{
System.out.println("Unknown Host Name!");
System.exit(0);
}
catch (IOException e)
{
System.out.println("Error:"+e.getMessage());
}
}
public static void main(String[] args) {
Client client=new Client("168.168.168.32",85);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -