コード例 #1
0
ファイル: ClientHandler.cs プロジェクト: TominoCZ/SharpStrike
        public ClientHandler(string ip, int port)
        {
            var udp = new UdpClient();
            var tcp = new TcpClient();

            udp.Connect(ip, port);

            tcp.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);

            _wrapperUdp = new UdpWrapper(udp, port);
            _wrapperUdp.OnReceivedMessage += OnReceivedUdpMessage;
            _wrapperTcp = new TcpClientWrapper(tcp);
            _wrapperTcp.OnReceivedMessage += OnReceivedTcpMessage;

            tcp.Connect(ip, port);
        }
コード例 #2
0
        public ServerHandler(int port, int tickRate = 64)
        {
            _tickrate = tickRate;

            var udp = new UdpClient(port);
            var tcp = new TcpListener(IPAddress.Any, port);

            tcp.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
            tcp.Start();

            _wrapperUdp = new UdpWrapper(udp, port);
            _wrapperUdp.OnReceivedMessage += OnReceivedUdpMessage;

            _wrapperTcp = new TcpServerWrapper(tcp);
            _wrapperTcp.OnReceivedMessage += OnReceivedTcpMessage;
            _wrapperTcp.OnClientConnected += OnClientConnected;

            LoadMap();

            RunLoop();
        }