public async static Task <TcpConnection> ConnectAsync(INetStatCollector netStatCollector = null, string debugName = null)
        {
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            var localEndPoint = new IPEndPoint(IPAddress.Loopback, 0);

            socket.Bind(localEndPoint);

            var port = TcpConnection.PORT;

            var remoteEndPoint = new IPEndPoint(IPAddress.Loopback, port);

            await Task.Factory.FromAsync(socket.BeginConnect, socket.EndConnect, remoteEndPoint, null);

            return(new TcpConnection(socket, netStatCollector, debugName));
        }
Beispiel #2
0
		public TcpConnection(Socket socket, INetStatCollector netStatCollector = null, string debugName = null)
		{
			trace.Header = socket.RemoteEndPoint.ToString();
			m_netStatCollector = netStatCollector;

			trace.TraceInformation("New Connection");

			if (socket.Connected == false)
				throw new Exception();

			m_socket = socket;
			m_netStream = new GameNetStream(socket);

			m_deserializerThread = new Thread(DeserializerMain);
			m_deserializerThread.Name = debugName;
			m_deserializerThread.Start();
		}
        public TcpConnection(Socket socket, INetStatCollector netStatCollector = null, string debugName = null)
        {
            trace.Header       = socket.RemoteEndPoint.ToString();
            m_netStatCollector = netStatCollector;

            trace.TraceInformation("New Connection");

            if (socket.Connected == false)
            {
                throw new Exception();
            }

            m_socket    = socket;
            m_netStream = new GameNetStream(socket);

            m_deserializerThread      = new Thread(DeserializerMain);
            m_deserializerThread.Name = debugName;
            m_deserializerThread.Start();
        }
Beispiel #4
0
		public async static Task<TcpConnection> ConnectAsync(INetStatCollector netStatCollector = null, string debugName = null)
		{
			var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

			var localEndPoint = new IPEndPoint(IPAddress.Loopback, 0);
			socket.Bind(localEndPoint);

			var port = TcpConnection.PORT;

			var remoteEndPoint = new IPEndPoint(IPAddress.Loopback, port);

			await Task.Factory.FromAsync(socket.BeginConnect, socket.EndConnect, remoteEndPoint, null);

			return new TcpConnection(socket, netStatCollector, debugName);
		}