public void TestSSLConnection() { _server = new ButtplugWebsocketServer(); _server.StartServer(this, 12346, true, true); _client = new ButtplugTestClient("Test client"); _client.Connect(new Uri("wss://localhost:12346/b******g"), true).Wait(); var msgId = _client.NextMsgId; var res = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult(); Assert.True(res != null); Assert.True(res is Core.Messages.Test); Assert.True(((Core.Messages.Test)res).TestString == "Test string"); Assert.True(((Core.Messages.Test)res).Id > msgId); // Check ping is working Thread.Sleep(400); msgId = _client.NextMsgId; res = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult(); Assert.True(res != null); Assert.True(res is Core.Messages.Test); Assert.True(((Core.Messages.Test)res).TestString == "Test string"); Assert.True(((Core.Messages.Test)res).Id > msgId); Assert.True(_client.NextMsgId > 4); // Shut it down _client.Disconnect().Wait(); _server.StopServer(); }
public void StartServer() { try { _ws.StartServer(_bpFactory, (int)_port, _secure); ConnToggleButton.Content = "Stop"; SecureCheckBox.IsEnabled = false; PortTextBox.IsEnabled = false; } catch (SocketException e) { MessageBox.Show(e.Message, "B******g Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
public async void StartServer() { try { await _ws.StartServer(_bpFactory, 1, (int)_port, _loopback, _secure, _hostname); ConnToggleButton.Content = "Stop"; SecureCheckBox.IsEnabled = false; PortTextBox.IsEnabled = false; LoopbackCheckBox.IsEnabled = false; _connUrls.Clear(); _connUrls.Add(new ConnUrlData(_secure, "localhost", _port)); if (!_loopback) { foreach (var network in NetworkInterface.GetAllNetworkInterfaces()) { foreach (IPAddressInformation address in network.GetIPProperties().UnicastAddresses) { if (address.Address.AddressFamily == AddressFamily.InterNetwork && !IPAddress.IsLoopback(address.Address)) { _connUrls.Add(new ConnUrlData(_secure, address.Address.ToString(), _port)); } } } } ConnStatus.Content = "(Not Connected)"; DisconnectButton.IsEnabled = false; ConnInfo.IsEnabled = true; // We've brought the server up, clear the error. ClearLastError(); } catch (SocketException e) { _currentExceptionMessage = e.Message; _log.LogException(e, true, _currentExceptionMessage); } catch (CryptographicException e) { _currentExceptionMessage = "Cannot start server with SSL. Try turning off SSL. The server can still be used with ScriptPlayer, but not web applications. If you need SSL, contact B******g Developers for support (see About Tab)."; _log.LogException(e, true, _currentExceptionMessage); } }
public void StartServer() { try { _ws.StartServer(_bpFactory, (int)_port, _secure); ConnToggleButton.Content = "Stop"; SecureCheckBox.IsEnabled = false; PortTextBox.IsEnabled = false; ConnectionUrl.Text = (_secure ? "wss" : "ws") + "://localhost:" + _port.ToString() + "/b******g"; TestUrl.Inlines.Clear(); TestUrl.Inlines.Add((_secure ? "https" : "http") + "://localhost:" + _port.ToString()); ConnInfo.Visibility = Visibility.Visible; } catch (SocketException e) { MessageBox.Show(e.Message, "B******g Error", MessageBoxButton.OK, MessageBoxImage.Exclamation); } }
public async void TestConnection() { var server = new ButtplugWebsocketServer(); server.StartServer(this); var client = new ButtplugTestClient("Test client"); await client.Connect(new Uri("ws://localhost:12345/b******g")); Console.WriteLine("test msg 1"); var msgId = client.nextMsgId; var res = await client.SendMsg(new Core.Messages.Test("Test string", msgId)); Assert.True(res != null); Assert.True(res is Core.Messages.Test); Assert.True(((Core.Messages.Test)res).TestString == "Test string"); Assert.True(((Core.Messages.Test)res).Id == msgId); // Check ping is working Thread.Sleep(400); Console.WriteLine("test msg 2"); msgId = client.nextMsgId; res = await client.SendMsg(new Core.Messages.Test("Test string", msgId)); Assert.True(res != null); Assert.True(res is Core.Messages.Test); Assert.True(((Core.Messages.Test)res).TestString == "Test string"); Assert.True(((Core.Messages.Test)res).Id == msgId); Assert.True(client.nextMsgId > 4); await client.RequestDeviceList(); Console.WriteLine("FINISHED CLIENT DISCONNECT"); // Shut it down await client.Disconnect(); server.StopServer(); }
public void StartServer() { try { _ws.StartServer(_bpFactory, (int)_port, _loopback, _secure, _hostname); ConnToggleButton.Content = "Stop"; SecureCheckBox.IsEnabled = false; PortTextBox.IsEnabled = false; LoopbackCheckBox.IsEnabled = false; _connUrls.Clear(); _connUrls.Add(new ConnUrlData(_secure, "localhost", _port)); if (!_loopback) { foreach (var network in NetworkInterface.GetAllNetworkInterfaces()) { foreach (IPAddressInformation address in network.GetIPProperties().UnicastAddresses) { if (address.Address.AddressFamily == AddressFamily.InterNetwork && !IPAddress.IsLoopback(address.Address)) { _connUrls.Add(new ConnUrlData(_secure, address.Address.ToString(), _port)); } } } } ConnStatus.Content = "(Not Connected)"; DisconnectButton.IsEnabled = false; ConnInfo.Visibility = Visibility.Visible; } catch (SocketException e) { _log.LogException(e, true, e.Message); } catch (CryptographicException e) { _log.LogException(e, true, e.Message); } }
public void TestConnection() { var eEvent = new AutoResetEvent(false); _subtypeMgr.AddDevice(new TestDevice(_logMgr, "A", "1")); _server = new ButtplugWebsocketServer(); _server.StartServer(this); _client = new ButtplugTestClient("Test client"); _client.Connect(new Uri("ws://localhost:12345/b******g")).Wait(); var msgId = _client.NextMsgId; var res = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult(); Assert.True(res != null); Assert.True(res is Core.Messages.Test); Assert.True(((Core.Messages.Test)res).TestString == "Test string"); Assert.True(((Core.Messages.Test)res).Id > msgId); // Check ping is working Thread.Sleep(400); msgId = _client.NextMsgId; res = _client.SendMsg(new Core.Messages.Test("Test string", msgId)).GetAwaiter().GetResult(); Assert.True(res != null); Assert.True(res is Core.Messages.Test); Assert.True(((Core.Messages.Test)res).TestString == "Test string"); Assert.True(((Core.Messages.Test)res).Id > msgId); res = _client.SendMsg(new Core.Messages.Test("Test string")).GetAwaiter().GetResult(); Assert.True(res != null); Assert.True(res is Core.Messages.Test); Assert.True(((Core.Messages.Test)res).TestString == "Test string"); Assert.True(((Core.Messages.Test)res).Id > msgId); Assert.True(_client.NextMsgId > 5); // Test that events are raised var scanningFinished = false; ButtplugClientDevice lastAdded = null; ButtplugClientDevice lastRemoved = null; _client.ScanningFinished += (aSender, aArg) => { scanningFinished = true; eEvent.Set(); }; _client.DeviceAdded += (aSender, aArg) => { lastAdded = aArg.Device; eEvent.Set(); }; _client.DeviceRemoved += (aSender, aArg) => { lastRemoved = aArg.Device; eEvent.Set(); }; _client.StartScanning().Wait(); Assert.Null(lastAdded); _subtypeMgr.AddDevice(new TestDevice(_logMgr, "B", "2")); eEvent.WaitOne(10000); eEvent.Reset(); Assert.NotNull(lastAdded); Assert.AreEqual("B", lastAdded.Name); Assert.True(!scanningFinished); _client.StopScanning().Wait(); eEvent.WaitOne(10000); eEvent.Reset(); Assert.True(scanningFinished); Assert.AreEqual(2, _client.Devices.Length); Assert.AreEqual("A", _client.Devices[0].Name); Assert.AreEqual("B", _client.Devices[1].Name); eEvent.Reset(); Assert.Null(lastRemoved); foreach (var dev in _devMgr._devices.Values) { if ((dev as TestDevice)?.Identifier == "2") { (dev as TestDevice).RemoveDevice(); } } eEvent.WaitOne(10000); eEvent.Reset(); Assert.NotNull(lastRemoved); Assert.AreEqual("B", lastRemoved.Name); Assert.AreEqual(1, _client.Devices.Length); Assert.AreEqual("A", _client.Devices[0].Name); // Shut it down _client.Disconnect().Wait(); _server.StopServer(); }