public void Disconnected() { if (state == TCP_Connection_State.TCPC_Connected) { this.state = TCP_Connection_State.TCPC_Disconnected; } }
//---------------------------------------------------------------------------------------------// //Public functions: //---------------------------------------------------------------------------------------------// public void Connected() { NET_Debug.InjectMessage("[NET_TCP_CN]", "[OK] Connected"); state = TCP_Connection_State.TCPC_Connected; this.thread = new Thread(TCP_ConnectionThread); this.thread.Name = "[NET_TCP] connection thread"; this.thread.Start(); }
//---------------------------------------------------------------------------------------------// //Private functions: //---------------------------------------------------------------------------------------------// private void TCP_ConnectionThread() { NET_Debug.InjectMessage("[NET_TCP_CN]", "[OK] Thread started"); //While connection established while (state == TCP_Connection_State.TCPC_Connected) { TCP_Receive(); TCP_Sending(); } client.Client.Disconnect(true); stream.Close(); stream.Dispose(); client.Close(); NET_Debug.InjectMessage("[NET_TCP_CN]", "[OK] Thread ended"); this.state = TCP_Connection_State.TCPC_DeleteMe; }
public void Disconnect(int playerID) { if (state == TCP_Connection_State.TCPC_Connected) { NET_Debug.InjectMessage("[NET_TCP_CN]", "[OK] Disconnected"); NET_Messages.NET_Message_Disconnect disconnectMessage = new NET_Messages.NET_Message_Disconnect(DateTime.Now); NET_DataPack pack = new NET_DataPack(); pack.SetData("PlayerID", playerID); disconnectMessage.SetData(pack.SerializeData()); lock (tcpOUT_MessageQueue) { tcpOUT_MessageQueue.Enqueue(disconnectMessage); } TCP_Sending(); this.state = TCP_Connection_State.TCPC_Disconnected; } }