private async System.Threading.Tasks.Task MakeDiscoverable() { // Make the system discoverable. Don'd repeatedly do this or the StartAdvertising will throw "cannot create a file when that file already exists" if (!App.IsBluetoothDiscoverable) { Guid BluetoothServiceUuid = new Guid("17890000-0068-0069-1532-1992D79BE4D8"); try { provider = await RfcommServiceProvider.CreateAsync(RfcommServiceId.FromUuid(BluetoothServiceUuid)); Windows.Networking.Sockets.StreamSocketListener listener = new Windows.Networking.Sockets.StreamSocketListener(); listener.ConnectionReceived += OnConnectionReceived; await listener.BindServiceNameAsync(provider.ServiceId.AsString(), Windows.Networking.Sockets.SocketProtectionLevel.PlainSocket); // SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication); // Don't bother setting SPD attributes provider.StartAdvertising(listener, true); App.IsBluetoothDiscoverable = true; } catch (Exception e) { string formatString = BluetoothDeviceInformationDisplay.GetResourceString("BluetoothNoDeviceAvailableFormat"); string confirmationMessage = string.Format(formatString, e.Message); DisplayMessagePanelAsync(confirmationMessage, MessageType.InformationalMessage); } } }
public async void StartListening() { try { _logger.NotifyUserInfo("TCPIP Listener", $"Started Listening on Port {_port}"); await _listener.BindServiceNameAsync(_port.ToString()); } catch (Exception ex) { _logger.NotifyUserError("TCPIP Listener", ex.Message); } }
protected override async void OnNavigatedTo(NavigationEventArgs e) { var streamSocketListener = new Windows.Networking.Sockets.StreamSocketListener(); streamSocketListener.ConnectionReceived += this.StreamSocketListener_ConnectionReceived; await streamSocketListener.BindServiceNameAsync("1337"); var streamSocket = new Windows.Networking.Sockets.StreamSocket(); await streamSocket.ConnectAsync(new Windows.Networking.HostName("localhost"), "1337"); this.SendMultipleBuffersInefficiently(streamSocket, "Hello, World!"); //this.BatchedSendsCSharpOnly(streamSocket, "Hello, World!"); //this.BatchedSendsAnyUWPLanguage(streamSocket, "Hello, World!"); }
public async void StartServer() { try { var streamSocketListener = new Windows.Networking.Sockets.StreamSocketListener(); // The ConnectionReceived event is raised when connections are received. streamSocketListener.ConnectionReceived += this.StreamSocketListener_ConnectionReceived; // Start listening for incoming TCP connections on the specified port. You can specify any port that's not currently in use. await streamSocketListener.BindServiceNameAsync(PortNumber); } catch (Exception ex) { Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult); } }
/// <summary> /// Used to start the stream socket listener and attach the event handler for incoming connections /// </summary> private async void StartServer() { try { streamSocketListener = new Windows.Networking.Sockets.StreamSocketListener(); // The ConnectionReceived event is raised when connections are received. streamSocketListener.ConnectionReceived += this.StreamSocketListener_ConnectionReceived; // Start listening for incoming TCP connections on the specified port. You can specify any port that's not currently in use. await streamSocketListener.BindServiceNameAsync(ConnectionPort.ToString()); System.Diagnostics.Debug.WriteLine("Listener started on port " + ConnectionPort); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Couldn't open socket listener."); } }
public async void CreateSocketListener() { try { // Create a StreamSocketListener to start listening for TCP connections. socketListener = new Windows.Networking.Sockets.StreamSocketListener(); // Hook up an event handler to call when connections are received. socketListener.ConnectionReceived += SocketListener_ConnectionReceived; // Start listening for incoming TCP connections on the specified port. You can specify any port that' s not currently in use. await socketListener.BindServiceNameAsync(portNum); } catch (Exception e) { Debug.WriteLine("CreateSocketListener() fault..."); // Handle exception. } }
private async void StartServer() { try { var streamSocketListener = new Windows.Networking.Sockets.StreamSocketListener(); // The ConnectionReceived event is raised when connections are received. streamSocketListener.ConnectionReceived += StreamSocketListener_ConnectionReceived; // Start listening for incoming TCP connections on the specified port. You can specify any port that's not currently in use. await streamSocketListener.BindServiceNameAsync(PortBox.Text); ShowMessage("server is listening..."); } catch (Exception ex) { Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult); ShowMessage(webErrorStatus.ToString() != "Unknown" ? webErrorStatus.ToString() : ex.Message); } }
/// <summary> /// creates TCP socket that is listening on port 7777 for requests /// requests will be handeled by SocketListener_ConnectionReceived /// </summary> private async Task createListenerAsync() { //Create a StreamSocketListener to start listening for TCP connections. Windows.Networking.Sockets.StreamSocketListener socketListener = new Windows.Networking.Sockets.StreamSocketListener(); //Hook up an event handler to call when connections are received. socketListener.ConnectionReceived += SocketListener_ConnectionReceived; Debug.WriteLine("create Listener"); try { //Start listening for incoming TCP connections on the specified port await socketListener.BindServiceNameAsync("7777"); Debug.WriteLine("created Listener"); } catch (Exception e) { //Handle exception. } }
/// <summary> /// Start the server and collect and respond to any incoming streams /// </summary> public void Start() { try { streamSocketListener = new Windows.Networking.Sockets.StreamSocketListener(); // The ConnectionReceived event is raised when connections are received. streamSocketListener.ConnectionReceived += this.ConnectionReceived; // Start listening for incoming TCP connections on the specified port. You can specify any port that's not currently in use. streamSocketListener.BindServiceNameAsync(this.portNumber); this.Output(MessageHelper.MessageType.Status, "server is listening on port \"" + this.portNumber + "\""); } catch (Exception ex) { // Lots of scary looking code here :/ // all that it says below is if you don't know what is going on write to buffer Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult); this.Output(MessageHelper.MessageType.Exception, webErrorStatus.ToString() != "Unknown" ? webErrorStatus.ToString() : ex.Message); } }
private async Task StartServer() { try { streamSocketListener = new Windows.Networking.Sockets.StreamSocketListener(); // The ConnectionReceived event is raised when connections are received. streamSocketListener.ConnectionReceived += this.StreamSocketListener_ConnectionReceived; // Start listening for incoming TCP connections on the specified port. You can specify any port that's not currently in use. await streamSocketListener.BindServiceNameAsync(SocketServerTerminalPage.PortNumber); //_Mode = Mode.JustConnected; status.Text = "Server is listening..."; } catch (Exception ex) { Windows.Networking.Sockets.SocketErrorStatus webErrorStatus = Windows.Networking.Sockets.SocketError.GetStatus(ex.GetBaseException().HResult); status.Text = webErrorStatus.ToString() != "Unknown" ? webErrorStatus.ToString() : ex.Message; } }
private async void Button_Click(object sender, RoutedEventArgs e) { try { Debug.WriteLine("provo a connettermi"); //Create a StreamSocketListener to start listening for TCP connections. Windows.Networking.Sockets.StreamSocketListener socketListener = new Windows.Networking.Sockets.StreamSocketListener(); //Hook up an event handler to call when connections are received. socketListener.ConnectionReceived += SocketListener_ConnectionReceived; //Start listening for incoming TCP connections on the specified port. You can specify any port that' s not currently in use. await socketListener.BindServiceNameAsync("10000"); Debug.WriteLine("connesso"); } catch (Exception er) { Debug.WriteLine("ops..."); Debug.WriteLine(er.Message); } }
public async Task StartListeningAsync() { _listener = new Windows.Networking.Sockets.StreamSocketListener(); _listener.ConnectionReceived += _listener_ConnectionReceived; await _listener.BindServiceNameAsync(_listenPort.ToString()); }
private async System.Threading.Tasks.Task MakeDiscoverable() { // Make the system discoverable. Don'd repeatedly do this or the StartAdvertising will throw "cannot create a file when that file already exists" if (!App.IsBluetoothDiscoverable) { Guid BluetoothServiceUuid = new Guid("17890000-0068-0069-1532-1992D79BE4D8"); try { provider = await RfcommServiceProvider.CreateAsync(RfcommServiceId.FromUuid(BluetoothServiceUuid)); Windows.Networking.Sockets.StreamSocketListener listener = new Windows.Networking.Sockets.StreamSocketListener(); listener.ConnectionReceived += OnConnectionReceived; await listener.BindServiceNameAsync(provider.ServiceId.AsString(), Windows.Networking.Sockets.SocketProtectionLevel.PlainSocket); // SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication); // Don't bother setting SPD attributes provider.StartAdvertising(listener, true); App.IsBluetoothDiscoverable = true; } catch (Exception e) { string formatString = BluetoothDeviceInformationDisplay.GetResourceString("BluetoothNoDeviceAvailableFormat"); string confirmationMessage = string.Format(formatString, e.Message); DisplayMessagePanel(confirmationMessage, MessageType.InformationalMessage); } } }