private void ListenForClients() { this.tcpListener.Start(); while (true) { //blocks until a client has connected to the server TcpClient client = this.tcpListener.AcceptTcpClient(); Client c = new Client(this.IdClientConnected, client); //create a thread to handle communication //with connected client this.ModuleH.addClientInRoom(0, this.IdClientConnected, client); Thread clientThread = new Thread(new ParameterizedThreadStart(HandleClientComm)); clientThread.Start(c); this.IdClientConnected += 1; } }
//以下为客户端消息 private static GetNoticeEventArgs GetClientSystem(Client owner) { GetNoticeEventArgs e = new GetNoticeEventArgs(owner, Attribute.ClientSystem); return e; }
public static GetNoticeEventArgs GetReceiveFromSevers(Client sender, string msg) { GetNoticeEventArgs e = new GetNoticeEventArgs(sender, Attribute.ReceiveFromSevers); e.commucateMessage = msg; e.content = String.Format("ReceiveFromSevers,{0}", msg); e.message = String.Format("接收到服务器内容:\r\n{0}", msg); return e; }
public static GetNoticeEventArgs GetSendToSevers(Client sender, string msg) { GetNoticeEventArgs e = new GetNoticeEventArgs(sender, Attribute.SendToSevers); e.commucateMessage = msg; e.content = String.Format("Send,{0}", msg); e.message = String.Format("向服务器发送:\r\n{0}", msg); return e; }
public static GetNoticeEventArgs GetExit(Client sender, IPEndPoint ipEndPoint) { GetNoticeEventArgs e = GetClientSystem(sender); e.content = String.Format("Exit,{0},{1}", ipEndPoint.Address.ToString(), ipEndPoint.Port); e.message = String.Format("叶隐!成功关闭了与服务器的连接!\\(^o^)/YES!"); return e; }
/// <summary> /// 某User的大数据包接收失败 /// </summary> /// <param name="sender"></param> /// <returns></returns> public static GetNoticeEventArgs GetLongDataReceiveFail(Client sender) { GetNoticeEventArgs e = GetClientSystem(sender); e.content = string.Format("LongDataReceiveFail"); e.message = string.Format("服务器发来的数据太长了……我吃不下QAQ求重发"); return e; }
public static GetNoticeEventArgs GetConnectSucceed(Client sender, IPEndPoint ipEndPoint) { GetNoticeEventArgs e = GetClientSystem(sender); e.content = String.Format("ConnectSucceed,{0},{1}", ipEndPoint.Address.ToString(), ipEndPoint.Port); e.message = "嘟嘟噜~找到服务器姐姐了~哦哈呦~~O(∩_∩)O~~"; return e; }
public GetNoticeEventArgs(Client owner, Attribute attribute) { this.clientOwner = owner; this.attribute = attribute; }
public static GetNoticeEventArgs GetConnectLost(Client sender, IPEndPoint ipEndPoint) { GetNoticeEventArgs e = GetClientSystem(sender); e.content = String.Format("ConnectLost,{0},{1}", ipEndPoint.Address.ToString(), ipEndPoint.Port); e.message = String.Format("噫!少年你气场太强大了!搞得我和服务器失联了!坏人~( TロT)σ"); return e; }
public static GetNoticeEventArgs GetConnectFailed(Client sender, IPEndPoint ipEndPoint) { GetNoticeEventArgs e = GetClientSystem(sender); e.content = String.Format("ConnectFailed,{0},{1}", ipEndPoint.Address.ToString(), ipEndPoint.Port); e.message = "(o゜▽゜)o☆索敌失败!并没有找到服务器sama。"; return e; }
public static GetNoticeEventArgs GetCloseClient(Client sender) { GetNoticeEventArgs e = GetClientSystem(sender); e.content = string.Format("CloseClient"); e.message = string.Format("这里刚刚释放了与服务端连接的资源_(:з」∠)_。"); return e; }