📄 msg.java
字号:
import java.io.Serializable;
import java.util.Date;
public class Msg implements Serializable{
protected int type;
protected String from;
protected String to;
protected Date time;
protected String content;
public static int MSG = 0;
public static int HANDSHAKE = 1;
public static int TEST = 2;
public static int OK = 4;
public static int LIST = 8;
public static int EXIT = 16;
public Msg(){
}
public Msg(int tp, String f, String t, String c){
type = tp;
from = f;
to = t;
time = new Date();
content = c;
}
public Msg(String f, String t, String c){
type = MSG;
from = f;
to = t;
time = new Date();
content = c;
}
public static Msg HANDSHAKEMSG(String name){
return new Msg(HANDSHAKE,name,"server","Hello!");
}
public static Msg TESTMSG(String name){
String to;
if(name == "server") to = "client";
else to = "server";
return new Msg(TEST,name,to,"Is you are here?");
}
public static Msg OKMSG(String name){
String to;
if(name == "server") to = "client";
else to = "server";
return new Msg(OK,name,to,"Yes!");
}
public static Msg LISTMSG(String name){
String to;
if(name == "server") to = "client";
else to = "server";
return new Msg(LIST,name,to,"List all the client.");
}
public static Msg LISTMSG(String name, String list){
String to;
if(name == "server") to = "client";
else to = "server";
return new Msg(LIST,name,to,"Clients on this server are :\n"+list);
}
public static Msg EXITMSG(String name){
String to;
if(name == "server") to = "client";
else to = "server";
return new Msg(EXIT,name,to,"I'll exit.");
}
public void settype(int tp){
type = tp;
}
public void setfrom(String f){
from = f;
}
public void setto(String t){
to = t;
}
public void settime(Date d){
time = d;
}
public void setcontent(String c){
content = c;
}
public int gettype(){
return type;
}
public String getfrom(){
return from;
}
public String getto(){
return to;
}
public Date gettime(){
return time;
}
public String getcontent(){
return content;
}
public String toString(){
String str = "From:"+from+"\nTo:"+to+"\nMessage:\n"+content;
return str;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -