I'm developing an app for WP7 which transmits UDP packets over the WIFI network. Everything works fine except a couple of the remote devices ignore the packets being sent to them as they are coming from an randomly assigned port number. As such I need to be able to set the local port number of the socket within my app.
As it stands the code looks like this where RemoteIP is either 2.255.255.255, 192.168.255.255 or a specific IP address in either the 2, 10 or 192.168 ranges. The port number is always 6454 which needs to be the local and remote port.
Much of the resources on the web and MSDN discuss methods that I don't think are available on Windows Phone 7.5 so I'm turning to you folks. As always your help is much appreciated.
Many thanks
Fraser
Dim _Socket As New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp)
Dim _done As New ManualResetEvent(False)
Dim HostEntry As New DnsEndPoint(RemoteIP, PortNumber)
Public Sub Send(Byval Data() as Byte)
If _Socket IsNot Nothing Then
Dim SocketEventArg As New SocketAsyncEventArgs
SocketEventArg.RemoteEndPoint = HostEntry
SocketEventArg.UserToken = Nothing
AddHandler SocketEventArg.Completed, AddressOf Callback
SocketEventArg.SetBuffer(data, 0, data.Length)
_done.Reset()
_Socket.SendToAsync(SocketEventArg)
_done.WaitOne(TimeOut)
End If
End Sub
Private Sub Callback(ByVal sender As Object, ByVal e As SocketAsyncEventArgs)
Select Case e.LastOperation
Case SocketAsyncOperation.Connect
Diagnostics.Debug.WriteLine("Connection Established to " & HostEntry.ToString)
Case SocketAsyncOperation.Send
Diagnostics.Debug.WriteLine("Packet Sent")
Case SocketAsyncOperation.Receive
Diagnostics.Debug.WriteLine("Packet Recieved")
Case Else
End Select
_done.Set()
End Sub

New Topic/Question
Reply


MultiQuote


|