public static async void Connection(TcpClient client, Gbl gbl) { try { await client.ConnectAsync(gbl.RemoteIpAddress, gbl.Port); } catch (Exception ex) { throw new SocketException(-1); } }
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; } }
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); }
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; } }