public void Connect(int id, string ip, int port, OnConnectionHandler connectCallback, OnConnectionHandler disconnectCallback) { if (mConnectionDic.ContainsKey(id)) { Connection client = mConnectionDic[id]; mConnectionDic.Remove(id); client.Close(true); } if (mConnectHandlerDic.ContainsKey(id)) { mConnectHandlerDic.Remove(id); } if (mDisconnectHandlerDic.ContainsKey(id)) { mDisconnectHandlerDic.Remove(id); } Connection c = new Connection(id); c.onConnect += OnConnect; c.onDisconnect += OnDisconnect; c.onDebug += OnDebug; c.onReceive += OnMessage; mConnectionDic.Add(id, c); mConnectHandlerDic.Add(id, connectCallback); mDisconnectHandlerDic.Add(id, disconnectCallback); c.Connect(ip, port); }
public NetBase() { Port = "8888"; Timer timer = new Timer(OnTimer, new ServerState(), 5000, 30000); OnData += new OnDataHandler(HandleNewData); OnConnection += new OnConnectionHandler(HandleNewConnection); }
public NetBase() { Port = "8888"; Timer timer = new Timer(OnTimer, new ServerState(), 5000, 30000); OnData += new OnDataHandler(HandleNewData); OnConnection += new OnConnectionHandler(HandleNewConnection); }
public void Connect(ConnectID varConnectID, string ip, int port, OnConnectionHandler onConnect, OnConnectionHandler onDisconnect) { int id = (int)varConnectID; if (mConnectionDic.ContainsKey(id)) { Connection client = mConnectionDic[id]; mConnectionDic.Remove(id); client.Close(true); } Connection c = new Connection(varConnectID); c.onConnect += onConnect; c.onDisconnect += onDisconnect; c.onDebug += OnDebug; c.onReceive += OnMessage; c.Connect(ip, port); mConnectionDic.Add(id, c); }
/// <summary> /// Add a new method to be called when the onconnection request is submitted /// </summary> /// <param name="activity"></param> public void RegisterOnConnectionTask(OnConnectionHandler activity) { onConnectionActivities.Add(activity); }