NetUDPclient commmunication library

Discussion in 'Additional Libraries' started by agraham, Aug 19, 2008.

  1. agraham

    agraham Expert Licensed User

    The library is a lightweight network library that wraps the .NET UDPclient object. It provide non-guaranteed network communication but absorbs less resources than TCP clients such as the Network library.

    For local interprocess communication this library may be easier to use than the Network library as the data arrives in packets, so no streams to parse, and a receive event is provided, so no polling.

    Help, demo and source included.

    EDIT:- Version 1.1 posted that supports IPv6 addresses. As this needs .NET 2.0 version 1.0 of the library is left available for use on .NET 1.0/1.1. See post #15 for details.

    EDIT:- This library is now deprecated. Its functionality is now included in the newly posted

    Attached Files:

    Last edited: Jul 30, 2009
  2. Byak@

    Byak@ Active Member Licensed User

  3. jesb4ppc

    jesb4ppc Member Licensed User

    Good Job.

    Hi agraham,

    You gave us what I was looking for since January.

    Maybe we should raise a statue to you (and Erel, of course), at least in Second Life. ;)

    Thank you very much.

  4. agraham

    agraham Expert Licensed User

    You should have mentioned it :(. I'd been playing with UDP for a while but only knocked up the help and posted a library when Byak wanted some interprocess communication.
  5. jesb4ppc

    jesb4ppc Member Licensed User

    Where to mention?

    Hi Agraham,

    You're right. Maybe I should have put it on the WishList, but I did on Questions and Help needed. :signOops:

    Anyway, thank you very much once again. :sign0098:
  6. agraham

    agraham Expert Licensed User

    I am afraid that I must have missed (or ignored at the time) your original post in Questions and Help but I do occasionally look back at the wishlist to see if what I am playing with might be useful to somebody.
  7. jerryet

    jerryet New Member Licensed User

    UDP client help


    I have used your udp client and it works great. I am however seeing one problem which I was hoping you could help me with.

    When I start a client like this:
    udpclient.Start(txtTargetIP.Text, txtRemote.Text, txtLocal.Text)

    and send a packet:

    Everything works fine....unicast packet sent...unicast packet recieved...receive event fires and I capture return packet string.

    Now, when I start a client like this:
    udpclient.Start("", txtRemote.Text, txtLocal.Text)

    and send:

    With a packet sniffer (Wireshark) I see a broadcast packet sent.....a unicast packet recieved....however no receive event is generated.

    I can give more details and wireshark capture if needed. It may be some simple answer like the dll will not work with a broadcast packet. Oh...BTW, I also used the following method to send a broadcast and it failed:

    udpclient.Start("", txtRemote.Text, txtLocal.Text)

    (the return string is....

    This all works when using VB6 and winsocket on the PC

  8. agraham

    agraham Expert Licensed User

    It's not entirely clear whether you are on the desktop or device. I'm not really a networking expert and the MSDN docs. are not explicit on this. However I think that probably the .NET 1.0/1.1 UDPCLient, which is what the library exposes, does not support Broadcasting. This is because only the .NET 2.0 Full Framework (desktop) UPDClient has an EnableBroadcast property which the neither Full nor Compact Frameworks version 1.0/1.1 have.

    If you are running under .NET 2.0 on the desktop, which you are if your app is optimised compiled or is legacy compiled using a config.exe file (which it should be) and have .NET 2.0 installed, then you could try this with the Door library. Note that I haven't tried this myself so it may not work.

    obj1 is a Door library Object.
    obj1.FromLibrary (
    "udpclient""client", B4PObject(2))
  9. Hitec

    Hitec Member Licensed User

    Problems with IPv4 / IPv6

    Hi Agraham,

    I'm using your library to send GPS-data to a server. Now there was something that was really strange. When I sent the using my GPRS/UMTS connection everything worked fine. When using my Wifi-Connection I always received an exception. First I thought that it could not resolve the DNS so I had a deeper look into it.

    What I found out is that when I was using the Wifi, I received an IPv6 address. If now I was doing a DNS request the request resolved an IPv6 address which seemed to be not accepted by your library.

    Is it possible that the library can be changed to support IPv6 addresses (I think its more complex) or just modify your library to send IPv4 DNS-Requests only.


  10. agraham

    agraham Expert Licensed User

    I can't test this but I have done the simplest thing and added a new method that I hope will work with IPv6 addresses. Try this before I update the help and repost it properly.

    StartIPv6(URLorIP As String, txPort As Int32, rxPort As Int32)

    URLorIP is string that contains a URL expected to resolve to an IPv6 address or an IP address in IPv6 colon-hexadecimal notation.

    This will now only work on devices with .NET 2.0 as Compact Framework 1.0 doesn't support IPv6.

    Attached Files:

  11. Hitec

    Hitec Member Licensed User

    Hey Thanks.

    Will try this right now...

    Have already integrated the new method. But when I try to compile I get an error that the "NetUDPclient.UDPclient does not contain a definition for StartIPv6". I use optimized compiling. Do I need to use normal compiling for this now?

  12. Hitec

    Hitec Member Licensed User

    OK, I tried it and it is working.

    I now first use the StartIPv6 method. If I get an exception there I'll use the regular Start method. This provides me exactly what I needed. Thanks a lot.

    Can you make the DLL now that I can use it with optimized compiling. Otherwise I can not use Threads and other stuff...

    Thanks a lot :icon_clap:

  13. agraham

    agraham Expert Licensed User

    Because I only posted an updated dll and I guess that you still have the old source file in your Basic4ppc Llibrary folder that the optimising compiler is trying to use. Delete that source file and you will be able to optimise compile but will need to place the temporary dll with the exe in the device folder to run it. Now I know it works I'll think about adding a way to to do a DNS lookup and detect whether an IPv4 or IPv6 address is returned and maybe a couple of other tweaks. When I post it as the next version it will of course include updated source and help file.
  14. Hitec

    Hitec Member Licensed User

    OK. It worked now

    Thanks a lot.

  15. agraham

    agraham Expert Licensed User

    Version 1.1 is now posted. This version supports IPv6 addresses and because of this needs .NET 2.0 or later as .NET 1.0/1.1 doesn't support IPv6.

    A new method, UdpClient.StartIPv6 that assumes IPv6 addressing is added.

    A new object, IpAddress is added that takes a URL, does a DNS lookup and can return an IPv4 or IPv6 address for use with either Start or StartIpv6 together with a flag showing which type of address the IpAddress represents.
  16. jesb4ppc

    jesb4ppc Member Licensed User

    Broadcast UDP

    Hi Agraham,

    I've been reading Jerryet port (#7), and I'm also interested in UDP Broadcasting.

    I've added your code (in desktop with .net 2.0.50727.1433) to the netudpdemo.sbp, as it shows below:

    Sub Globals
    'Declare the global variables here.
    End Sub

    Sub App_Start
    obj1.FromLibrary ("udpclient", "client", B4PObject(2))
    obj1.SetProperty("EnableBroadcast", "True")
    End Sub
    ...... (the same code of netdemo...)

    but got the attached image error.

    So, I changed to:

    obj1.FromLibrary ("Main.udpclient", "client", B4PObject(2))

    And got another error:

    "Object reference not established as an object instance"

    So, t seems it can´t recognize the udpclient object to set the property EnableBroadcast to True.

    Sure I'm doing wrong, 'cause I'm not quite sure how to use the door library, but do you have any idea of how to get UDP Broadcasting to work?:confused: It's a feature with a lot of applications.


    Thank you for your time once again.

    BTW, UDPClient 1.1 only works in basic4ppc 6.8 version. It took me a little to realize that doesn´t work in 6.5 version; it's just an advice for others who may get an error.

    Attached Files:

  17. agraham

    agraham Expert Licensed User

    The "client" field is not instantiated until Start is invoked as its' constructor takes the port number. Try this. As you found out the Door library wants the name of the module that the object belongs to.
    udpclient.Start(tbHost.Text, tbTxPort.Text, tbRxPort.Text)
    obj1.FromLibrary (
    "[COLOR="Red"]Main[/COLOR].udpclient""client", B4PObject(2))
    Broadcasting, if it works, is only available on the desktop.

    The library should work with earlier versions of Basic4ppc as long as .NET 2.0 is available. It is the demo sources that are 6.80 specific as their format changed.
  18. jesb4ppc

    jesb4ppc Member Licensed User

    Hi Andrew,

    Yes, it has to be instated first...:BangHead: I must be blind.

    I've tried it and I get communications in the same host if the tbhost.text in sender is and tbhost.text is also

    But what I was looking for is the sender to use an specific ip address (like or an external ipaddress) and the server in this address to receive from any address (like or; that's it: an UDP Server which can receive from any address. Is it possible with this library?

    Be or not possible, thank you once again for your time and your fast response.

  19. agraham

    agraham Expert Licensed User

    It's not presently possible but I have knocked up a UDPserver object that seems to work OK so I'll polish it up a bit, do the help and post a new version of the library in a day or so.
  20. agraham

    agraham Expert Licensed User

    Last edited: Jul 30, 2009
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice