예제 #1
0
        public static SessionVdS Run(IPEndPoint endPoint, CancellationToken token)
        {
            if (endPoint == null)
            {
                Log.Warn("No endpoint given, using default...");
                endPoint = new IPEndPoint(IPAddress.Loopback, 8888);
            }

            var client = new TcpClient();

            try
            {
                Log.Info("Connecting to: " + endPoint);
                client.Connect(endPoint);
            }
            catch (Exception ex)
            {
                Log.ErrorException(string.Format("Connecting to:  {0} failed", endPoint), ex);
                return(null);
            }

            var stream = client.GetStream();
            //var session = new SessionVdS(stream, isServer: false, keyNumber: 3);
            var session = new SessionVdS(stream, isServer: false, keyNumber: 0);

            session.Run();
            return(session);
        }
예제 #2
0
        public static void Run(IPEndPoint endPoint, CancellationToken token)
        {
            if (endPoint == null)
            {
                endPoint = new IPEndPoint(IPAddress.Any, 8888);
            }

            Task.Run(
                () =>
            {
                var listener = new TcpListener(endPoint);
                listener.Start();

                Console.WriteLine("Listening at: " + endPoint);
                while (!token.IsCancellationRequested)
                {
                    var client = listener.AcceptTcpClient();
                    if (!client.Connected)
                    {
                        Console.WriteLine("Error accepting TCP socket");
                        continue;
                    }

                    var stream  = client.GetStream();
                    var session = new SessionVdS(stream, true, 0);
                    session.Run();

                    Thread.Sleep(100);

                    // create sync request
                    session.SendRequest(InformationId.SyncReq);

                    // create poll requests
                    while (!token.IsCancellationRequested)
                    {
                        session.SendRequest(InformationId.PollReqRes);
                        Thread.Sleep(3000);
                    }
                }
            });
        }