コード例 #1
0
        //Start the tcp server
        private async Task TcpServerStart()
        {
            try
            {
                //Set the server endpoint
                IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Any, vSocketServerPort);

                //Start tcp server
                vTcpServer = new TcpListener(serverEndPoint);
                vTcpServer.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                vTcpServer.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
                vTcpServer.Server.LingerState = new LingerOption(true, 0);
                vTcpServer.Start();

                Debug.WriteLine("Tcp server is running on (S): " + serverEndPoint.Address + ":" + serverEndPoint.Port);

                //Start receive loop
                AVActions.TaskStartLoop(TcpReceiveLoop, vTask_TcpReceiveLoop);

                //Start clean loop
                AVActions.TaskStartLoop(TcpCleanLoop, vTask_TcpCleanLoop);
            }
            catch (Exception ex)
            {
                await SocketServerException(ex);
            }
        }
コード例 #2
0
        //Start the udp server
        private async Task UdpServerStart()
        {
            try
            {
                //Set the server endpoint
                IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Any, vSocketServerPort);

                //Start udp server
                vUdpServer = new UdpClient(serverEndPoint);

                Debug.WriteLine("Udp server is running on (S): " + serverEndPoint.Address + ":" + serverEndPoint.Port);

                //Start receive loop
                AVActions.TaskStartLoop(UdpReceiveLoop, vTask_UdpReceiveLoop);

                //Start clean loop
                AVActions.TaskStartLoop(UdpCleanLoop, vTask_UdpCleanLoop);
            }
            catch (Exception ex)
            {
                await SocketServerException(ex);
            }
        }