コード例 #1
0
        public Server(HostEndPoint endPoint)
        {
            // TODO: remove this from here.
            FloodNetwork.NetworkInitialize();

            var server = new HostServer();

            host = server;

            var details = new HostConnectionDetails()
            {
                Address      = endPoint.Address,
                Port         = endPoint.Port,
                ChannelCount = ChannelCount
            };

            server.SessionPacket += OnPacket;
            server.CreateSocket(details);
        }
コード例 #2
0
        public async Task <bool> Connect(HostEndPoint endPoint, int timeout = 1000)
        {
            // TODO: remove this from here.
            FloodNetwork.NetworkInitialize();

            var client = new HostClient();

            host = client;

            var tcs = new TaskCompletionSource <bool>();

            var session = client.Session;

            session.StateChange += state =>
            {
                if (state == SessionState.Open)
                {
                    tcs.SetResult(true);
                }
            };

            var details = new HostConnectionDetails()
            {
                Address      = endPoint.Address,
                Port         = endPoint.Port,
                ChannelCount = ChannelCount
            };

            client.Connect(details);

            // Wait for task somewhere else
            if (await Task.WhenAny(tcs.Task, Task.Delay(timeout)) != tcs.Task)
            {
                return(false);
            }

            client.SessionPacket += OnPacket;

            Log.Info("Client connected with session!");
            return(true);
        }