NetUDPclient commmunication library

agraham

Expert
Licensed User
Longtime 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 http://www.b4x.com/forum/additional-libraries/4658-netudp-server-client-library.html#post26758
 

Attachments

  • NetUDPclient1.0.zip
    13 KB · Views: 132
  • NetUDPclient1.1.zip
    14.4 KB · Views: 43
Last edited:

Byak@

Active Member
Licensed User

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.

:sign0188:
 

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:
 

agraham

Expert
Licensed User
Longtime User
Maybe I should have put it on the WishList, but I did on Questions and Help needed
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.
 

jerryet

New Member
Licensed User
UDP client help

Agraham,

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:
udpclient.SendString("yelL1",0)

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("255.255.255.255", txtRemote.Text, txtLocal.Text)

and send:
udpclient.SendString("find",0)

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("192.168.1.255", txtRemote.Text, txtLocal.Text)
udpclient.SendString("find",0)

(the return string is....192.168.1.200)

This all works when using VB6 and winsocket on the PC

Thanks,
Jerry
 

agraham

Expert
Licensed User
Longtime 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.
B4X:
obj1.New1(False)
  ....
obj1.FromLibrary ("udpclient", "client", B4PObject(2))
obj1.SetProperty("EnableBroadcast", "True")
 

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.

Thanks

Thomas
 

agraham

Expert
Licensed User
Longtime 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.
 

Attachments

  • NetUDPclient1.01.zip
    2.6 KB · Views: 18

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?

Thanks
Thomas
 

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:

Thomas
 

agraham

Expert
Licensed User
Longtime User
I get an error that the "NetUDPclient.UDPclient does not contain a definition for StartIPv6".
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.
 

agraham

Expert
Licensed User
Longtime 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.
 

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
Form1.Show
udpclient.New1
obj1.New1(False)
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.

:sign0085:

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.
 

Attachments

  • UDPBCAST_ERR1.JPG
    UDPBCAST_ERR1.JPG
    18 KB · Views: 11

agraham

Expert
Licensed User
Longtime 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.
B4X:
udpclient.Start(tbHost.Text, tbTxPort.Text, tbRxPort.Text)
obj1.FromLibrary ("[COLOR="Red"]Main[/COLOR].udpclient", "client", B4PObject(2))
obj1.SetProperty("EnableBroadcast", "True")
Broadcasting, if it works, is only available on the desktop.

BTW, UDPClient 1.1 only works in basic4ppc 6.8 version.
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.
 

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 127.0.0.255 and tbhost.text is also 127.0.0.255.

But what I was looking for is the sender to use an specific ip address (like 127.0.0.1 or an external ipaddress) and the server in this address to receive from any address (like 255.255.255.255 or 127.0.0.255); 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.

:sign0188:
 

agraham

Expert
Licensed User
Longtime User
an UDP Server which can receive from any address. Is it possible with this library?
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.
 
Top