public void connect(string hostAddress, int iPort) { try { this.chatClient = new ChatClientControl(); if (this.chatClient.connect(hostAddress, iPort)) { ChatJoinObject chatJoin = new ChatJoinObject(); chatJoin.Username = this.user; this.chatClient.sendDataObject(chatJoin); } } catch (Exception) { lblWarning.Text = "Kết nối tới máy chủ thất bại!"; isConnect = false; } }
private void runServer() { while (this.chatServerControl != null && this.chatServerControl.isConnected()) { try { Socket socketChannel = this.chatServerControl.acceptChannel(); System.Threading.Thread.Sleep(200); SocketChannel channel = new SocketChannel(this.txtLog, this.mqRequestQueue); ChatJoinObject chatJoinObjcet = (ChatJoinObject)channel.recvDataObject(socketChannel); channel.startChannel(socketChannel); channel.logMonitor(DateTime.Now + " -Username: "******" is connected! \r\n"); this.mhSessionTable.Add(chatJoinObjcet.Username, channel); } catch (Exception e) { Console.Write(e.Message); } System.Threading.Thread.Sleep(300); } }
public void connect(string hostAddress, int iPort) { try { this.chatClient = new ChatClientControl(); if (this.chatClient.connect(hostAddress, iPort)) { ChatJoinObject chatJoin = new ChatJoinObject(); chatJoin.Username = this.username; this.chatClient.sendDataObject(chatJoin); ThreadStart threadStart = new ThreadStart(runRecvData); Thread thread = new Thread(threadStart); thread.IsBackground = true; thread.Start(); threadStart = new ThreadStart(sendRefresh); thread = new Thread(threadStart); thread.IsBackground = true; thread.Start(); threadStart = new ThreadStart(sendLoadMessage); thread = new Thread(threadStart); thread.IsBackground = true; thread.Start(); } } catch (Exception e) { Console.WriteLine(e.Message); } }