예제 #1
0
 /// <summary>
 /// Constractor
 /// </summary>
 /// <param name="bindIPAddress">local ip address bind in this socket</param>
 /// <param name="remoteIPEndPoint">remote IPEndPoint</param>
 public SingleConnection(IPAddress bindIPAddress, IPEndPoint remoteIPEndPoint)
 {
     this.BindIPEndPoint     = new IPEndPoint(bindIPAddress, 0);
     this.RemoteIPEndPoint   = remoteIPEndPoint;
     DefaultDataSerializer   = new Serialize.BinSerializer <object>();
     DefaultReturnSerializer = new Serialize.JsonSerializer <DataContainer>();
 }
예제 #2
0
        public SingleConnectionCable(IPEndPoint remoteIPEndPoint, int capacity)
        {
            RemoteIPEndPoint = remoteIPEndPoint;

            if (capacity <= 0)
            {
                throw new ArgumentException("Capacity must be large than 0");
            }

            Capacity = capacity;

            _WorkingAsyncConnections  = new LinkedList <SingleConnection>();
            _PendingAsyncConnections  = new Queue <SingleConnection>();
            _CurrentWorkingConnection = null;

            for (int i = 1; i < capacity; i++)
            {
                SingleConnection conn = new SingleConnection(remoteIPEndPoint);

                conn.ErrorEventHandler += InnerErrorEventHandler;

                conn.ReceiveEventHandler += InnerReceiveEventHandler;

                conn.RemoteDisconnected += InnerRemoteDisconnected;

                _PendingAsyncConnections.Enqueue(conn);
            }

            DefaultDataSerializer   = new Serialize.BinSerializer <object>();
            DefaultReturnSerializer = new Serialize.JsonSerializer <DataContainer>();

            _SyncConnection = new SingleConnection(remoteIPEndPoint);

            _SyncConnection.ErrorEventHandler += InnerErrorEventHandler;

            _SyncConnection.ReceiveEventHandler += InnerReceiveEventHandler;

            _SyncConnection.RemoteDisconnected += InnerRemoteDisconnected;

            _ConnectThread = new System.Threading.Thread(ConnectThreadProc);
            _ConnectThread.IsBackground = true;
            _ConnectThread.Start();
        }