JumpyNET Posted December 31, 2013 Posted December 31, 2013 (edited) I have put up a simple DatagramSocket test example with separate solutions/projects for client and server. Sending strings from client to server is working but sending a string from server to client results in the following error: "A method was called at an unexpected time. (Exception from HRESULT: 0x8000000E)" What could be the problem ??? Source code for the UDP Client (Windows Phone 8 App) Partial Public Class MainPage : Inherits PhoneApplicationPage Dim WithEvents Soketti As DatagramSocket Private Async Sub ButtonConnect_Click(sender As Object, e As RoutedEventArgs) Handles ButtonConnect.Click Soketti = New DatagramSocket Await Soketti.ConnectAsync(New HostName("192.168.1.7"), "4321") End Sub Private Sub Soketti_MessageReceived(sender As DatagramSocket, args As DatagramSocketMessageReceivedEventArgs) Handles Soketti.MessageReceived Dim reader As DataReader = args.GetDataReader Dim actualStringLength As UInteger = reader.UnconsumedBufferLength Dim MsgReceived As String = reader.ReadString(actualStringLength) System.Diagnostics.Debug.WriteLine(MsgReceived) End Sub Private Async Sub ButtonSend_Click(sender As Object, e As RoutedEventArgs) Handles ButtonSend.Click Dim stringToSend As String = "Some Text To Send" Dim writer As New DataWriter(Soketti.OutputStream) writer.WriteString(stringToSend) Await writer.StoreAsync() writer.DetachStream() writer.Dispose() End Sub End Class Source code for the UDP Server (Windows 8.0 Store App) Public NotInheritable Class MainPage : Inherits Page Dim WithEvents not_just_a_listener As DatagramSocket Private Async Sub ButtonListen_Click(sender As Object, e As RoutedEventArgs) Handles ButtonListen.Click not_just_a_listener = New DatagramSocket Await not_just_a_listener.BindServiceNameAsync("4321") End Sub Private Sub listener_MessageReceived(sender As DatagramSocket, args As DatagramSocketMessageReceivedEventArgs) Handles not_just_a_listener.MessageReceived Dim reader As DataReader = args.GetDataReader Dim actualStringLength As UInteger = reader.UnconsumedBufferLength Dim MsgReceived As String = reader.ReadString(actualStringLength) Debug.WriteLine(MsgReceived) End Sub Private Async Sub ButtonSend_Click(sender As Object, e As RoutedEventArgs) Handles ButtonSend.Click Dim stringToSend As String = "Some Text Back" Dim writer As New DataWriter(not_just_a_listener.OutputStream) writer.WriteString(stringToSend) Await writer.StoreAsync() ' ** This will crash *** writer.DetachStream() writer.Dispose() End Sub End Class Edited December 31, 2013 by JumpyNET Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.