0 Replies - 12084 Views - Last Post: 29 February 2012 - 01:21 PM

#1 Conno  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 3
  • Joined: 25-January 12

WP7 Local EndPoint Socket Issue

Posted 29 February 2012 - 01:21 PM


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, 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


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)
        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
    End Sub

Is This A Good Question/Topic? 0
  • +

Page 1 of 1