public override void Init() { base.Init(); mData = GetData(); mClient = BeetleX.ServerFactory.CreateTcpClient(Config.Host, Config.Port); mClient.ClientError = OnNetError; mClient.Receive = OnReceive; }
public static void Main(string[] args) { BeetleX.Clients.IClient client = ServerFactory.CreateTcpClient("127.0.0.1", 9090); client.Receive = (c, e) => { lock (e.SyncObject) { Console.WriteLine(e.ReadLine()); } }; client.Connect(); client.Writer.WriteLine(DateTime.Now.ToString()); client.Writer.Flush(); Console.Read(); }
public void Open() { try { mRouteCenter = new RouteCenter(); mRouteCenter.Register(this); if (!System.IO.Directory.Exists(UNIT_TESTCASE_PATH)) { System.IO.Directory.CreateDirectory(UNIT_TESTCASE_PATH); } mServerClient = BeetleX.ServerFactory.CreateTcpClient <Network.ClientPacket>(ServerHost, ServerPort); mNodeServer = BeetleX.ServerFactory.CreateTcpServer <NodeApp, Network.Packet>(mNetConfig); mNodeServer.Handler = this; while (!mNodeServer.Open()) { mNodeServer.Config.Port++; } Loger.Process(LogType.INFO, "Note network start!"); LoadProcessAgent(); Loger.Process(LogType.INFO, "Note load unittest completed!"); mServerClient.ClientError = OnServerError; mServerClient.ConnectedServer = OnServerConnect; mServerClient.Packet.Completed = OnPacketCompleted; if (mServerClient.Connect()) { Loger.Process(LogType.INFO, "Note connect to {0}", ServerHost); } else { Loger.Process(LogType.ERROR, "Note connect to {0} error {1}", ServerHost, mServerClient.LastError.Message); } this.Performance.Open(); } catch (Exception e_) { Loger.Process(LogType.INFO, "Note network start error {0}", e_.Message); } if (mPingTimer != null) { mPingTimer.Dispose(); } mPingTimer = new System.Threading.Timer(PingServer, this, 1000, 1000); }
private void OnServerError(BeetleX.Clients.IClient client, Exception e, string message) { Loger.Process(LogType.ERROR, "Note network start error {0}", e.Message); }