Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Problems with UdpClient

Problems with UdpClient

Scheduled Pinned Locked Moved Visual Basic
sysadminquestionworkspace
8 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DK KiloDunse
    wrote on last edited by
    #1

    I have 2 computer i a LAN, witch is connected to the internet. Comp1. Ip = 192.168.0.195 Comp2. Ip = 192.168.0.163 My router is set up to forward port 12000 to comp2. Comp1 acts as a server. It sends data using UDPClient. 'Uses the IP address and port number to establish a socket connection. udpClient = New UdpClient Dim ipAddress As IPAddress = Dns.Resolve("my internet IPaddress").AddressList(0) Try udpClient.Connect(ipAddress, 12000) Catch ex As Exception Console.WriteLine(ex.ToString()) End Try udpClient.Send(Data, Data.Length) Comp2 acts as a client. It receives data using UDPClient. Dim receivingUdpClient As New UdpClient(12000) Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0) Do Try Data = receivingUdpClient.Receive(RemoteIpEndPoint) ... .... Comp2 doesn’t receive anything. BUT... if Comp1 is setup like this 'Uses the IP address and port number to establish a socket connection. udpClient = New UdpClient Dim ipAddress As IPAddress = Dns.Resolve("192.168.0.163").AddressList(0) Try udpClient.Connect(ipAddress, 12000) Catch ex As Exception Console.WriteLine(ex.ToString()) End Try udpClient.Send(Data, Data.Length) Then it works. The only changes I made is, instead of using my internet adr. I used my locale adr. Any idea why???

    D 1 Reply Last reply
    0
    • D DK KiloDunse

      I have 2 computer i a LAN, witch is connected to the internet. Comp1. Ip = 192.168.0.195 Comp2. Ip = 192.168.0.163 My router is set up to forward port 12000 to comp2. Comp1 acts as a server. It sends data using UDPClient. 'Uses the IP address and port number to establish a socket connection. udpClient = New UdpClient Dim ipAddress As IPAddress = Dns.Resolve("my internet IPaddress").AddressList(0) Try udpClient.Connect(ipAddress, 12000) Catch ex As Exception Console.WriteLine(ex.ToString()) End Try udpClient.Send(Data, Data.Length) Comp2 acts as a client. It receives data using UDPClient. Dim receivingUdpClient As New UdpClient(12000) Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0) Do Try Data = receivingUdpClient.Receive(RemoteIpEndPoint) ... .... Comp2 doesn’t receive anything. BUT... if Comp1 is setup like this 'Uses the IP address and port number to establish a socket connection. udpClient = New UdpClient Dim ipAddress As IPAddress = Dns.Resolve("192.168.0.163").AddressList(0) Try udpClient.Connect(ipAddress, 12000) Catch ex As Exception Console.WriteLine(ex.ToString()) End Try udpClient.Send(Data, Data.Length) Then it works. The only changes I made is, instead of using my internet adr. I used my locale adr. Any idea why???

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      I would double check the router configuration to make sure that it is indeed sending the information to the correct local IP address. Also, make sure that the default gateway on the machines in the local IP address of the router. And, finally, do you have any firewall software running on the machines? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

      D 1 Reply Last reply
      0
      • D Dave Kreskowiak

        I would double check the router configuration to make sure that it is indeed sending the information to the correct local IP address. Also, make sure that the default gateway on the machines in the local IP address of the router. And, finally, do you have any firewall software running on the machines? RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

        D Offline
        D Offline
        DK KiloDunse
        wrote on last edited by
        #3

        I can see the data is ariving at the client... LAN-connection in the traybar but the program doesn't receive the data. NetLimiter shows that the client program has NO connections.

        D 1 Reply Last reply
        0
        • D DK KiloDunse

          I can see the data is ariving at the client... LAN-connection in the traybar but the program doesn't receive the data. NetLimiter shows that the client program has NO connections.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          Once again, do you have a firewall running on that machine? If so, disable it and see what happens... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

          D 1 Reply Last reply
          0
          • D Dave Kreskowiak

            Once again, do you have a firewall running on that machine? If so, disable it and see what happens... RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

            D Offline
            D Offline
            DK KiloDunse
            wrote on last edited by
            #5

            No firewall's at all. and turned off in router. Is it cuz i'm sending and receiving on the same internet ip-address? (just for testing) :confused:

            D 1 Reply Last reply
            0
            • D DK KiloDunse

              No firewall's at all. and turned off in router. Is it cuz i'm sending and receiving on the same internet ip-address? (just for testing) :confused:

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              I've got a strange feeling about this one. Try your code from a test machine outside your router. Try it on a friends machine from his/her house connecting back to your internet IP address. I get the feeling that either the router is still misconfigured somehow, or there's something you haven't told us about your UDP connection. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

              D 2 Replies Last reply
              0
              • D Dave Kreskowiak

                I've got a strange feeling about this one. Try your code from a test machine outside your router. Try it on a friends machine from his/her house connecting back to your internet IP address. I get the feeling that either the router is still misconfigured somehow, or there's something you haven't told us about your UDP connection. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                D Offline
                D Offline
                DK KiloDunse
                wrote on last edited by
                #7

                ok, thanks. I'm making a small prog witch sends data to my internet ip every 3 sec. Then running the prog from another computer (diff. IP). And a little prog. witch try's to receive the data, and running it from my computer.

                1 Reply Last reply
                0
                • D Dave Kreskowiak

                  I've got a strange feeling about this one. Try your code from a test machine outside your router. Try it on a friends machine from his/her house connecting back to your internet IP address. I get the feeling that either the router is still misconfigured somehow, or there's something you haven't told us about your UDP connection. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome

                  D Offline
                  D Offline
                  DK KiloDunse
                  wrote on last edited by
                  #8

                  Hmmm....:wtf: The only code that works is: Dim rxSocket As Socket = Nothing Dim RecvBytes(1000) As Byte Dim RemoteEP As New IPEndPoint(0, 0) Dim myCallback As New AsyncCallback(AddressOf OnReceive) Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load rxSocket = New Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp) RemoteEP = New IPEndPoint(IPAddress.Any, 12000) rxSocket.Bind(RemoteEP) rxSocket.BeginReceiveFrom(RecvBytes, 0, RecvBytes.Length, _ SocketFlags.None, RemoteEP, myCallback, Nothing) End Sub Public Sub OnReceive(ByVal ar As IAsyncResult) Dim iBytes As Integer Try Catch e As SocketException MsgBox(e.Message) Exit Sub End Try ListView1.Items.Add(System.Text.Encoding.UTF8.GetString(RecvBytes)) iBytes = rxSocket.EndReceiveFrom(ar, RemoteEP) rxSocket.BeginReceiveFrom(RecvBytes, 0, RecvBytes.Length, _ SocketFlags.None, RemoteEP, myCallback, Nothing) End Sub But thanks for your help

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups