public void Start(SimulationModelInfo simModel, ref SimulationEventDistributor distributor, string logName, bool loop) { try { playerThread = new Thread(new ThreadStart(EventLoop)); //nc = new NetworkClient(); //nc.Connect(hostname, port); distClient = new SimulationEventDistributorClient(); distributor.RegisterClient(ref distClient); this.simModel = simModel; time = 0; this.loop = loop; this.logname = logName; updateFrequency = simModel.simulationExecutionModel.updateFrequency; SimulationEvent ev = SimulationEventFactory.BuildEvent(ref simModel, "ResetSimulation"); distClient.PutEvent(ev); LoadEvents(logName); playerThread.Start(); } catch (Exception e) { throw e; } }
private void ConnectionHandler() { NetMessage m = new NetMessage(); SimulationEvent e = null; while (true) { try { m.Receive(ref netStream); switch (m.type) { case NetMessageType.REGISTER: eventDistClient = new SimulationEventDistributorClient(); networkServer.eventDist.RegisterClient(ref eventDistClient); m_terminalID = m.TerminalID; m.type = NetMessageType.REGISTER_RESPONSE; //m.clientID = networkServer.RegisterClient(); m.clientID = eventDistClient.id; m.Send(ref netStream, m.TerminalID); break; case NetMessageType.SUBSCRIBE: eventDistClient.Subscribe(m.msg); break; case NetMessageType.EVENT: try { e = SimulationEventFactory.XMLDeserialize(m.msg); eventDistClient.PutEvent(e); } catch (Exception exc) { ErrorLog.Write(String.Format("NONFATAL Deserialize Error in NetworkServer: {0}", m.msg)); ErrorLog.Write(exc.ToString()); } //networkServer.EventFromClient(e); break; case NetMessageType.DISCONNECT: //netStream.Close(0); System.Console.WriteLine("NetworkServerConnectionHandler.ConnectionHandler:connection closed"); //netStream.Dispose(); //networkServer.RemoveClient(eventDistClient.id); sendThread.Abort(); ForceClose(); return; case NetMessageType.NONE: ErrorLog.Write(String.Format("NONFATAL Deserialize Error in NetworkServer: {0}", m.msg)); ErrorLog.Write(String.Format("TYPE: {0}; MSG: {1};",m.type, m.msg)); break; default: throw new Exception("connection handler got an invalid event"); } } catch (System.IO.IOException exc) { System.Console.WriteLine("NetworkServerConnectionHandler.ConnectionHandler:lost connection with client"); ForceClose(); return; } catch (System.ObjectDisposedException) { return; } catch (ThreadAbortException) { return; } catch (Exception exc) { MessageBox.Show("An error has occured in the Simulation Server.\nPlease email the C:\\DDDErrorLog.txt file to Aptima customer support with a description of what you were doing at the time of the error."); ErrorLog.Write(exc.ToString() + "\n"); throw new Exception(); } } }