Liberty BASIC Community Forum
« UDP comunications »

Welcome Guest. Please Login or Register.
Dec 12th, 2017, 08:14am


Rules|Home|Help|Search|Recent Posts|Notification


« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: UDP comunications  (Read 204 times)
papa3110
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 2
xx UDP comunications
« Thread started on: Jun 3rd, 2016, 11:29am »

I'm trying to use the SimpleSocket dll with liberty basic.
I have VB code but having a hard time translating code.
Here is the VB

Receiver

Set socket=WScript.CreateObject("SimpleSocket.Udp", "event_")
Sub event_OnReceive(data)
WScript.Echo "Received: " & data
End Sub

socket.Listen "127.0.0.1", 10000
While(True)
WScript.Sleep(5000)
Wend
socket.Abort

Sender

Set socket=WScript.CreateObject("SimpleSocket.Udp")
socket.Send "127.0.0.1", 10000, "Data sent from the client"

Could anyone show me what I need for LB?

Thanks smiley
User IP Logged

Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2289
xx Re: UDP comunications
« Reply #1 on: Jun 4th, 2016, 3:42pm »

I'll look for some sample code I have that shows how to use UDP communications.


It is, unfortunately, fairly complex code, though. We have simpler to use libraries for TCP use(See Mesock32, I believe), but I don't think it supported UDP.
User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
papa3110
New Member
Image


member is offline

Avatar




PM

Gender: Male
Posts: 2
xx Re: UDP comunications
« Reply #2 on: Jun 6th, 2016, 2:09pm »

I do have code using WS2_32.dll that works with Liberty Basic for sending UDP and it works great

open "WS2_32" for DLL as #winsock

packet$ = ":33,b"+chr$(10)+chr$(13)
ok = UDPsend("172.16.16.51",1001, packet$)
if ok then print "Packet sent" else print "UDPsend failed"
print packet$
close #winsock
end

function UDPsend(addr$, port, msg$)
AF.INET = 2
SOCK.DGRAM = 2
IPPROTO.UDP = 17
UDPsend = 0

port = (port and hexdec("FF00")) / 256 + (port and 255) * 256 ' swap bytes
calldll #winsock, "inet_addr", addr$ as ptr, ipaddr as ulong

struct WSAdata, d as char[398]
calldll #winsock, "WSAStartup", 514 as long, WSAdata as struct, ret as long
if ret then exit function

calldll #winsock, "socket", AF.INET as long, SOCK.DGRAM as long, _
IPPROTO.UDP as long, socket as long
if socket = -1 then exit function

struct addr, family as short, port as short, addr as ulong, zero as char[8]
addr.family.struct = AF.INET
addr.port.struct = port
addr.addr.struct = ipaddr
print port
print AF.INET
print ipaddr


al = len(addr.struct)
ml = len(msg$)
print ipaddr
print ml

calldll #winsock, "sendto", socket as long, msg$ as ptr, ml as long, _
0 as long, addr as struct, al as long, sent as long

calldll #winsock, "closesocket", socket as long, ret as long
calldll #winsock, "WSACleanup", ret as long

if sent = ml then UDPsend = 1
end function


maybe that would be the better dll to use?
User IP Logged

Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2289
xx Re: UDP comunications
« Reply #3 on: Jun 6th, 2016, 10:18pm »

That's fairly certain to the code I have lying around. (Sorry, it's been a busy week. Preparing for a trip to Seattle)

WS2_32 is the Winsock library, which is the official way to do network programming in Win32.
« Last Edit: Jun 6th, 2016, 10:22pm by Chris Iverson » User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: UDP comunications
« Reply #4 on: Dec 7th, 2017, 10:14am »

Works great, I want to use it to send data to an arduino.

Is it possible to skip the popup screen when you send something?
User IP Logged

Chris Iverson
Administrator
ImageImageImageImageImage


member is offline

Avatar

20% Cooler


Homepage PM

Gender: Male
Posts: 2289
xx Re: UDP comunications
« Reply #5 on: Dec 7th, 2017, 11:22am »

What popup screen are you speaking of? I don't see anything in here that would be popping something up.
User IP Logged

"Do you believe in destiny?" - Pyrrha Nikos, RWBY
"With what wish will your Soul Gem shine?" - Kyubey, Puella Magi Madoka Magica
Konijn
New Member
Image


member is offline

Avatar




PM


Posts: 6
xx Re: UDP comunications
« Reply #6 on: Dec 7th, 2017, 2:09pm »

Hello Chris,

I see it, I was doing it wrong. I am sorry. I was copying this code in to my code and that goes wrong. rolleyes

Thanks Jack
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Rules|Home|Help|Search|Recent Posts|Notification

Donate $6.99 for 50,000 Ad-Free Pageviews!

| |

This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls