public void ClientThread(object context) { Main.gameMenu = true; Main.menuMode = 888; Main.MenuUI.SetState(new UINetworkConnection()); object[] parameter = (object[])context; bool exitThread = false; DimPlayer player = (DimPlayer)parameter[0]; int numberOfAttempt = 0; RemoteAddress adress = new TcpAddress(Netplay.ServerIP, 7776); ClientLoopSetup(adress); ISocket secondarySocket = new TcpSocket(); secondarySocket.Connect(new TcpAddress(Netplay.ServerIP, 7776)); while (!exitThread) { try { Thread.Sleep(2500); if (secondarySocket.IsDataAvailable()) { byte[] data = new byte[ushort.MaxValue]; secondarySocket.AsyncReceive(data, 0, ushort.MaxValue, new SocketReceiveCallback(Netplay.Connection.ClientReadCallBack), null); using (MemoryStream stream = new MemoryStream(data)) { BinaryReader reader = new BinaryReader(new MemoryStream(data)); } numberOfAttempt++; } else { byte[] data = new byte[ushort.MaxValue]; using (MemoryStream stream = new MemoryStream(data)) { BinaryWriter writer = new BinaryWriter(stream); writer.Write("hey"); secondarySocket.AsyncSend(writer.BaseStream.ReadAllBytes(), 0, ushort.MaxValue, new SocketSendCallback(Netplay.Connection.ClientWriteCallBack), null); } } } catch (Exception e) { LogManager.GetLogger("Second thread").Error(e.Message, e); } } Netplay.Connection.Socket.Close(); Netplay.StartTcpClient(); player.inTransit = false; }