Beispiel #1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="addr">user IP address, e.g. 192.168.1.13</param>
 /// <param name="status">nvcp operation status ready/busy</param>
 /// <param name="time">Current time</param>
 /// <param name="token">initial value of token, used for autorization</param>
 public SubscriberItem(IPEndPoint addr, nvcpOperStatus status, DateTime time, int token)
 {
     this.address = addr;
     this.status  = status;
     this.token   = token;
     this.time    = time;
 }
Beispiel #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="type">nvcp operation: connect/check avability</param>
 /// <param name="state">nvcp operation status</param>
 /// <param name="data">optional data e.g. IP address</param>
 public NVCP(nvcpOperation type, nvcpOperStatus state, string data = "")
 {
     this.version         = 0x01;
     this.operationStatus = state;
     this.operationType   = type;
     this.protocolStatus  = IStatus.OK;
     this.timeStamp       = DateTime.Now;
     this.data            = data;
 }
Beispiel #3
0
        /*<summary>
         * send to server login and status and return response from server
         */
        private NVCP Send_MYSTATUS(nvcpOperStatus status)
        {
            TcpClient client    = new TcpClient(Form1.machineName, _control_port);
            SslStream sslStream = new SslStream(
                client.GetStream(),
                false,
                new RemoteCertificateValidationCallback(Form1.ValidateServerCertificate),
                null
                );

            try
            {
                sslStream.AuthenticateAsClient(Form1.serverName);
            }
            catch (AuthenticationException e)
            {
                Console.WriteLine("Exception: {0}", e.Message);
                if (e.InnerException != null)
                {
                    Console.WriteLine("Inner exception: {0}", e.InnerException.Message);
                }
                Console.WriteLine("Authentication failed - closing the connection.");
                client.Close();
            }
            NVCP sendFrame = new NVCP(nvcpOperation.MY_STATUS, status, login + ' ' + user_token.ToString());

            byte[] sendBytes = Encoding.ASCII.GetBytes(sendFrame.ToString());
            sslStream.Write(sendBytes);
            sslStream.Flush();
            byte[] buffer = new byte[1500];
            sslStream.Read(buffer, 0, buffer.Length);
            NVCP frame = new NVCP(Encoding.ASCII.GetString(buffer, 0, buffer.Length));

            tokenupdate(frame);
            return(frame);
        }