private void Listen() { #if OFFLINE { var x = @"C:\Users\James\Desktop\convo.raw"; using (var fs = File.OpenRead(x)) { using (Reader = new EndianBinaryReader(new LittleEndianBitConverter(), fs)) { Palace = new ClientPalace(this); while (fs.Position < fs.Length) { var cm = Reader.ReadStruct<ClientMessage>(); HandleMessage(cm); } foreach (var bt in blowthrus) { using (var ws = File.OpenWrite(@"C:\Users\James\Desktop\blowthrus" + blowthrus.IndexOf(bt) + ".raw")) { foreach (var b in bt) ws.WriteByte(b); ws.Flush(); } } } } } #endif while (!listenerToken.IsCancellationRequested) { try { _connection = new TcpClient(targetUri.Host, targetUri.Port); Palace = new ClientPalace(this); using (var stream = _connection.GetStream()) { Handshake(stream, reset); using (Reader) using (Writer) { //var op_msg = new MH_SMsg("This client is running Taj DEBUG build. Please notify Scorpion of any questions or concerns."); //op_msg.Write(Writer); //Debug.WriteLine("OP_SMSG sent"); //var timer = new Timer(o => { connection.Close(); }, null, 6000, 3000); Connected(this, new EventArgs()); while (!listenerToken.IsCancellationRequested) { //try //{ var msg = Reader.ReadStruct<ClientMessage>(); Debug.WriteLine("Message: " + Enum.GetName(typeof(MessageTypes), msg.eventType)); Debug.WriteLine("{"); Debug.Indent(); HandleMessage(msg); Debug.Unindent(); Debug.WriteLine("}"); //} //catch (AggregateException ae) //{ // foreach (var ie in ae.InnerExceptions) // if (ie is ObjectDisposedException || ie is OperationCanceledException) // return; // throw; //} } if (_connection.Connected) Signoff(); } } Debug.WriteLine("Listening ended"); } catch (IOException e) { Trace.TraceError(e.ToString()); } finally { if (_connection != null) _connection.Close(); } } }