public NetRedirWS(Network net, string ToServer, int Port, string SessionID) { this.ToServer = ToServer; this.Port = Port; this.SessionID = SessionID; InitSuccess = false; try { IPAddress ip; IPHostEntry ipaddr; if (IPAddress.TryParse(ToServer, out ip) == false) { ipaddr = Dns.GetHostEntry(ToServer); } else { ipaddr = new IPHostEntry(); ipaddr.AddressList = new IPAddress[] { ip }; } if (ipaddr == null) { return; } if (ipaddr.AddressList.Length == 0) { return; } string URL = ProgramAgent.GetWSUrl(net) + "websocket/agent-" + Uri.EscapeUriString(SessionID); ws = new WebSocket(URL); ws.OnMessage += Ws_OnMessage; ws.SetCookie(new WebSocketSharp.Net.Cookie("Agent-SessionID", net.Session)); ws.Connect(); Debug.WriteLine("WSSOCKET: " + SessionID + " Create connection to " + ToServer + ":" + Port.ToString()); socket = new Socket(ipaddr.AddressList[0].AddressFamily, SocketType.Stream, ProtocolType.Tcp); socket.Connect(ipaddr.AddressList[0], Port); RunningRXThread = new Thread(new ThreadStart(RXThread)); RunningRXThread.Start(); } catch { CloseAll(); return; } InitSuccess = true; }
public ScreenDataWS(Network net, string SessionID) { this.SessionID = SessionID; if (SessionID != "TEST") { this.LastUpdated = DateTime.UtcNow; this.URL = ProgramAgent.GetWSUrl(net) + "websocket/agent-" + Uri.EscapeUriString(SessionID); this.NetSessionID = net.Session; if (ConnectWS() == false) { return; } } InitSuccess = true; }