View Full Version : UDP Client only for receiving data
Hello everybody - Iīm new to thinBasic (but not to Basic). Iīm searching for a simple UDP Client (only for receiving data!!) - Iīve tried the examples but they donīt work for me! Iīm trying to connect to my Raspberry Pi which is working well as a UDP-Server (I tried it with the hercules terminal!) Could somebody give me a hint how this could be done?
Thanks in advance!
ErosOlmi
29-02-2024, 08:13
Ciao,
have you tried sample scripts in \thinBasic\SampleScripts\TcpUdp\
There are 2 scripts and 1 include file:
UDP_Notify_Server.tbasic
UDP_Notify_Client.tbasic
UDP_Notify_Common.INC
The idea of this example is to use UDP to communicate from one (or more) client to a UDP server and once connected the client can control the position of the UDP server window
Start UDP_Notify_Server script and click on "I'm a server"
then run one client script UDP_Notify_Client and click on "Find server"
You should see them connecting and then if you move client window it will move server window
More than one client can be executed up to 10
Example works searching for server on localhost but can be changed to search for specific IP address
If not working:
one problem can be related to Firewalls: port used to communicate must be open for UDP protocol
Also under many Windows versions an application trying to open UDP or TCP ports as a client or as a server must be authorized as application.
Dear Eros,
as said before I tried all examples in TCPUDP-Directory!!
I found this code in your forum but itīs not working!
Uses "INet" '---Load INet module
Uses "RAS" '---Load RAS module
Uses "FILE" '---Load FILE module
Uses "TCPUDP" '---Load TCPUDP module
Uses "OS" '---Load OS module
Uses "CONSOLE" '---Load CONSOLE module
DIM pbxip AS LONG
DIM pbxname AS STRING
DIM udpconnid AS LONG
pbxip = HOSTNAME_TOIP("pbv01")
pbxname = HOSTIP_TONAME(pbxip)
Msg = "pbxip=" + pbxip + $CRLF
Msg += "pbxname=" + pbxname + $CRLF
MSGBOX(1,Msg)
udpconnid = UDP_Open(9009,UDP_FreeFile)
Do
INCR Count
sBuffer = UDP_Recv(udpconnid)
Msg = sBuffer
IF (Len(Msg) < 3) THEN
Msg = "hello"
END IF
MSGBOX(1,Msg)
Console_WriteLine Msg
Loop While ((Len(sBuffer) > 0) AND (ERR = 0))
UDP_Close(udpconnid)
Errormessage - Unknown Keyword or variable not defined
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
10332
This is a snapshot of an UDP-Client that I wrote in FreeBasic - thatīs what I want but as a graphical interface!!! It just connects to the server at 192.168.1.100 on Port 48000 and receives the data showing it in a DOS-Box! I changed to thinBasic because itīs just better - I should have done so from the beginning! For now it would be good to have a program running in a DOS-Box - the graphics can be done later! But because Iīm new to thinBasic itīs hard for me to find the right way!!
Ciao
Peter
ErosOlmi
01-03-2024, 00:18
I will work in the week-end on a simple script to test
I will work in the week-end on a simple script to test
Gracie mille Eros!!!
Cioa
Peter
ErosOlmi
02-03-2024, 23:19
Hope this can help.
Attached an UDP_Server script and UDP_Client. I've added both sources and bundled exe
Tried to keep as simple as possible to concentrate only on send/receive
UDP_Server
on start it will open UDP port 40000 on localhost 127.0.0.1 an wait for receiving some data
It will set a timeout of 10 seconds but will loop for next receive
Leave the server running waiting some data
UDP_Client
on start will send some data to localhost 127.0.0.1 port 40000
After sending will exit
You can run client many times to send some new data
Attention
windows firewall may interfere and scripts must be allowed to send/receive data
UDP Client is the one sending data
UPD Server is the one receiving data
PS:
thinBasic help UDP_OpenServer is wrong because it reported UDP_Open instead of UDP_OpenServer
I will fix next release.
Thank you so much Eros - thatīs a very fine example! I always thought I needed a client!! Now I know better!
The next step is to make the program "Windowish". I already made a GUI with your Visual Designer!
Ciao
Peter
Thereīs no way for me to bundle a program although they work fine in the thinBasic environment. I always get the same errormessage: " Errorcode: 12000 - Obfuscated script not valid. Decript Error code:3
Iīm using Windows 10 Professional!
ErosOlmi
04-03-2024, 07:37
I think this is my mistake in thinBasic 1.12.0 :oops:
Please download attached thinCore.dll and copy it into \thinBasic\ path substituting the one you have
It is thinCore 1.12.1 I'm working on and I will publish this week
Let me know if it works
Thank you again Eros,
I want to say that thinBasic is a superb Program - Itīs blistering fast and modern and your support is the best I ever had!!!!
ciao
Peter
ErosOlmi
04-03-2024, 13:12
Thanks Peter.
Very happy when we can help.
Soon a new thinBasic version 1.12.1 I'm working on.