?? client.java
字號:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;
import ocsf.AbstractClient;
/**
* @author new
*/
public class Client extends AbstractClient
{
private String name = "";
protected void handleMessageFromServer(Object msg)
{
/*
* Do something when receive message from server
*/
System.out.println("(" + name + ")" + (String) msg);
}
public Client(String name, String host, int port)
{
super(host, port);
this.name = name;
}
public void sendMsg(String msg)
{
/*
* Send a piece of message to server
*/
try
{
this.sendToServer(name + ":" + msg);
}
catch (IOException e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
int port=11111;
String host="127.0.0.1";
Client c1=new Client("c1",host,port);
try
{
//begin to connect to server
c1.openConnection();
System.out.println("Client started.");
//sending messages
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String s="";
System.out.println("Type sentences here, and type \"quit\" if you want to quit.");
while(true)
{
try
{
s=br.readLine();
if(s.equals("quit")) break;
//System.out.println("sending to server...");
c1.sendMsg(s);
//System.out.println("Done.");
}
catch (IOException e)
{
e.printStackTrace();
}
}
//close connection
c1.closeConnection();
System.out.println("Client finished.");
}
catch (IOException e)
{
e.printStackTrace();
}
}
public String getName()
{
return name;
}
public void setName(String name)
{
this.name = name;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -