Esempio n. 1
0
 public static async void Connection(TcpClient client, Gbl gbl)
 {
     try
     {
         await client.ConnectAsync(gbl.RemoteIpAddress, gbl.Port);
     }
     catch (Exception ex)
     {
         throw new SocketException(-1);
     }
 }
Esempio n. 2
0
        public static void ConnectToServer(Gbl gbl, out TcpSocketEx tcp)
        {
            var client = new TcpSocketEx(gbl.RemoteIpAddress, gbl.Port);

            try
            {
                client.Connect(IPAddress.Parse(gbl.RemoteIpAddress), gbl.Port);
                tcp = client;
            }
            catch (Exception e)
            {
                tcp = null;
            }
        }
Esempio n. 3
0
        public static bool SerialConfig(Gbl gbl, out Pcomm pcomm)
        {
            pcomm = new Pcomm();
            var hasht = new Hashtable()
            {
                { Pcomm.KEY_PORT, $"{gbl.SelectCom}" },
                { Pcomm.KEY_BAUDRATE, $"{gbl.SelectSpeed}" },
                { Pcomm.KEY_BYTESIZE, $"{gbl.SelectDataBits}" },
                { Pcomm.KEY_PARITY, $"{gbl.SelectParity}" },
                { Pcomm.KEY_STOPBITS, $"{gbl.SelectStopBits}" },
                { Pcomm.KEY_READINTERVALTIMEOUT, $"{gbl.IntevaTime}" },
                { Pcomm.KEY_READTOTALTIMEOUT, $"{gbl.TotalTime}" }
            };

            pcomm.InitComm(hasht);
            return(true);
        }
Esempio n. 4
0
        public static void Listen(Gbl gbl, out TcpClient tcpClient)
        {
            tcpClient = null;
            try
            {
                if (_tcpListener == null)
                {
                    _tcpListener = new TcpListener(IPAddress.Any, gbl.Port);
                    _tcpListener.Start();
                }

                _log.Debug($"Start TCP Listen...");
                //check the client's connection by cycle
                tcpClient = _tcpListener.AcceptTcpClient();


                _log.Debug($@"TCP Listen <----- {tcpClient}");
            }
            catch (Exception es)
            {
                _log.Error(es.Message);
                tcpClient = null;
            }
        }