コード例 #1
0
ファイル: NetworkManager.cs プロジェクト: Enanyy/moon
    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);
    }
コード例 #2
0
ファイル: netbase.cs プロジェクト: ajduncan/cs_netbase
 public NetBase()
 {
     Port          = "8888";
     Timer timer   = new Timer(OnTimer, new ServerState(), 5000, 30000);
     OnData        += new OnDataHandler(HandleNewData);
     OnConnection  += new OnConnectionHandler(HandleNewConnection);
 }
コード例 #3
0
        public NetBase()
        {
            Port = "8888";
            Timer timer = new Timer(OnTimer, new ServerState(), 5000, 30000);

            OnData       += new OnDataHandler(HandleNewData);
            OnConnection += new OnConnectionHandler(HandleNewConnection);
        }
コード例 #4
0
        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);
        }
コード例 #5
0
 /// <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);
 }