public void ConnectToServer(IPAddress ip, int port) { if (_webSocketConnection != null) return; _webSocketConnection = new WebSocket($"ws://{ip}:{port}"); _webSocketConnection.OnOpen += (sender, args) => { Connected?.Invoke(); }; _webSocketConnection.OnClose += (sender, args) => { Disconnected?.Invoke(); }; _webSocketConnection.OnMessage += (sender, args) => { if (args.IsText) { ReceivedTextMessage?.Invoke(args.Data); } else if (args.IsBinary) { ReceivedByteArrayMessage?.Invoke(args.RawData); } }; _webSocketConnection.OnError += (sender, args) => { ReceivedError?.Invoke(); }; _webSocketConnection.Connect(); }
public void ConnectToServer(string address, int port, bool isUsingSecureConnection) { if (_webSocketConnection != null) { return; } var urlPrefix = isUsingSecureConnection ? "wss" : "ws"; _webSocketConnection = new WebSocket($"{urlPrefix}://{address}:{port}/Listener"); _webSocketConnection.OnOpen += (sender, args) => { Connected?.Invoke(); }; _webSocketConnection.OnClose += (sender, args) => { Disconnected?.Invoke(); }; _webSocketConnection.OnMessage += (sender, args) => { if (args.IsBinary) { ReceivedByteArrayMessage?.Invoke(args.RawData); } }; _webSocketConnection.OnError += (sender, args) => { ReceivedError?.Invoke(); }; _webSocketConnection.Connect(); ConfigureNoDelay(); }