Beispiel #1
0
        /******************************************************************
         * purpose: initial tcp ip port
         * parameter:
         *   Input: serialPort - serial port ip address
         *          port - com port information
         *   Output:
         ********************************************************************/
        public TcpTimeServer(SerialPortControl serialPort, int port)
        {
            _port       = port;
            _serialPort = serialPort;

            Server();
        }
 protected override void OnStart(string[] args)
 {
     _serialPort = new SerialPortControl();
     if (!_serialPort.openComPort(comPort))
     {
         Trace.WriteLine(DateTime.Now + " Open com port failed! ");
         return;
     }
     tcpServer = new TcpTimeServer(_serialPort, Convert.ToInt32(port)); //11000
     StartService(this.ServiceName, 10000);
 }
Beispiel #3
0
        //public static Socket listener;

        public AsynchronousSocketListener(SerialPortControl serialPort, int port)
        {
            // Establish the local endpoint for the socket.
            // The DNS name of the computer
            // running the listener is "host.contoso.com".
            IPHostEntry ipHostInfo = Dns.GetHostEntry(Dns.GetHostName());
            //ipAddress = ipHostInfo.AddressList[4];//0 is mac address
            IPAddress ipAddress = IPAddress.Any;

            localIpEndPoint = new IPEndPoint(IPAddress.Any, port);

            // Create a TCP/IP socket.
            _socket = new Socket(ipAddress.AddressFamily,
                                 SocketType.Stream, ProtocolType.Tcp);

            Console.WriteLine("socket receive timeout: " + _socket.ReceiveTimeout);
            Console.WriteLine("socket send timeout: " + _socket.SendTimeout);
            _socket.Blocking = false;

            _serialPort = serialPort;
        }