ntech
New Member
Posts: 49
|
Post by ntech on Oct 5, 2019 10:24:34 GMT -5
HTTP/UDP/Sockets DLL v2.3 With Http Dll 2 you can send HTTP requests and read (or save) the results. It can also create sockets (normal sockets or listening sockets) and binary buffers, and communicate via UDP protocol. -Supports listening sockets (server) and normal sockets (client). -Supports IPv4 and IPv6. -Supports TCP and UDP. -Data via buffers. - Zlib compression for buffers. - Hexadecimal and base64 encoding/decoding. - c++ source code included -Licensed under GPL-DLL is 252.5KiB in size. - No dependencies.This DLL is very straightforward, and includes documentation for all its functions (except the HTTP part, which is un-documented as LB already has HTTP capabilities). This is much more straightforward and easy than winsock programming, as it's a wrapper on it. http-dll.zip (231.71 KB) Please note that members find this download has many problem, Rod. DISCLAIMER:
Http Dll 2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with Http Dll 2. If not, see <http://www.gnu.org/licenses/>.
|
|
|
Post by pandawdy on Oct 7, 2019 2:25:13 GMT -5
Is this meant to be used with Liberty Basic?
|
|
|
Post by tsh73 on Oct 7, 2019 2:52:24 GMT -5
Who is the author, is it you? Will be some LB code examples for it?
|
|
|
Post by pandawdy on Oct 7, 2019 9:02:14 GMT -5
I downloaded it but there are no code examples. It does have some documentation.
|
|
ntech
New Member
Posts: 49
|
Post by ntech on Oct 7, 2019 10:20:06 GMT -5
Is this meant to be used with Liberty Basic? Pandawdy, yes it's perfectly compatible with Liberty Basic. Its documentation provides everything necessary to use calldll. Who is the author, is it you? Will be some LB code examples for it? It's not all mine, however I made some slight modifications and compiled the distributed dll. The reason there's no code samples was because it's fairly easy to interact with the DLL via calldll, but here's three, one for each of: bufffers, sockets, and udpsockets: Buffer code:'Code to work with buffers.
open "http_dll_2_3.dll" for dll as #buffer
calldll #buffer, "buffer_create", result as double
bufferID = result 'the buffer id. important.
'Since we've created a buffer, we can now utilize it:
'For example, READ A DOUBLE from the buffer calldll #buffer, "buffer_read_float64", bufferID as double, return as double
'Then CLEAR BUFFER, before we write to it calldll #buffer, "buffer_clear", bufferID as double, return as double
'Finally, WRITE A DOUBLE to it val = 3.14 calldll #buffer, "buffer_write_float64", bufferID as double, val as double, return as double
'If we like, we can read that same value from it: calldll #buffer, "buffer_read_float64", bufferID as double, return as double
print "Returned: "+str$(return) 'shall print "3.14"
'FINALLY we have to destroy the buffer. calldll #buffer, "buffer_destroy", bufferID as double, return as double
close #buffer
Socket code:
'Code to work with sockets. Example is a client.
global socketID, bufferID
open "http_dll_2_3.dll" for dll as #sk
'First, create a buffer. calldll #sk, "buffer_create", return as double bufferID = return
'Then a socket. calldll #sk, "socket_create", return as double socketID = return
'Connect the socket to 127.0.0.1, port 12840 calldll #sk, "socket_connect", socketID as double, "127.0.0.1" as ptr, 12840 as double, return as double
while 1=1 'Continuously read and display what is sent over the socket, then echo it to the server.
'Read everything the socket has to offer into the buffer calldll #sk, "socket_read_message", socketID as double, bufferID as double, return as double 'Read the length of the buffer calldll #sk, "buffer_get_length", bufferID as double, return as double length = return
'Read the buffer calldll #sk, "buffer_read_data", bufferID as double, length as double, return as ptr data$ = winstring$(return) print data$
'Create a tmp buffer to store echo data. calldll #sk, "create_buffer", return as double
tmpBuffer = return
'Populate the buffer, in effect, an echo calldll #sk, "buffer_write_data", tmpBuffer as double, data$ as ptr, return as double
'Send the buffer over the socket calldll #sk, "socket_write_message", socketID as double, tmpBuffer as double, return as double
'Destroy the temporary buffer calldll #sk, "buffer_destroy", tmpBuffer as double, return as double
wend
close #sk UDP Code: 'Code to work with UDP. Sends a packet containing "hello udp!", which can optionally be zlip-compressed
global socketID, bufferID
open "http_dll_2_3.dll" for dll as #sk
'First, create a buffer. calldll #sk, "buffer_create", return as double bufferID = return
'Then a socket. calldll #sk, "udpsocket_create", return as double socketID = return
'Populate buffer with data calldll #sk, "buffer_write_string", bufferID as double, "hello udp!" as ptr, return as double
'If you like, uncomment the line below to gzip "deflate" compress the data. Sometimes this is useful. 'calldll #sk, "buffer_zlip_compress", socketID as double, return as double
'Start the socket, on port 1234. Note that THIS IS NOT THE PORT that it shall send data to. calldll #sk, "udpsocket_start", socketID as double, 0 as double, 1234 as double, return as double
'Set the destination: serverLocation port 4321 calldll #sk, "udpsocket_set_destination", socketID as double, "serverLocation" as ptr, 4321 as double, return as double
'Send data! calldll #sk, "udpsocket_send", socketID as double, bufferID as double, return as double
'Destroy the socket calldll #sk, "udpsocket_destroy", socketID as double, return as double
print "UDP Packet sent!"
close #sk
|
|
|
Post by pandawdy on Oct 7, 2019 20:18:31 GMT -5
The DLL has to be in the same folder I'm assuming. I did try the UDP code but it doesn't work.
Sorry if it sounds like I'm complaining. I'm not a really good programmer.
|
|
|
Post by tsh73 on Oct 8, 2019 1:16:21 GMT -5
Thank you for providing examples. (I did not tried it, may be later)
|
|
ntech
New Member
Posts: 49
|
Post by ntech on Oct 9, 2019 9:43:29 GMT -5
The DLL has to be in the same folder I'm assuming. I did try the UDP code but it doesn't work. Sorry if it sounds like I'm complaining. I'm not a really good programmer. Yep, the DLL Is referenced by a relative path (the absence of absolute path starting with drive name, "C:\\" for instance). What is the error message when you try the UDP code?
|
|
|
Post by pandawdy on Oct 12, 2019 14:35:09 GMT -5
The DLL has to be in the same folder I'm assuming. I did try the UDP code but it doesn't work. Sorry if it sounds like I'm complaining. I'm not a really good programmer. Yep, the DLL Is referenced by a relative path (the absence of absolute path starting with drive name, "C:\\" for instance). What is the error message when you try the UDP code? This is what happens when trying to execute the UDP code sample:
|
|
|
Post by Chris Iverson on Oct 12, 2019 14:38:49 GMT -5
return is a keyword, and can't be used as variable name.
Change it to ret or something similar.
|
|
|
Post by pandawdy on Oct 12, 2019 15:24:44 GMT -5
return is a keyword, and can't be used as variable name. Change it to ret or something similar. I had to change all of the RETURN's to something else.. but it does execute the code now. Thanks.
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Feb 1, 2020 5:13:06 GMT -5
I'm trying, without success!
To read UDP traffic on a specific port.
However I seem to have an issue reading the data as a PTR
The debugger halts and eventually LB crashes on this line;
calldll #sk, "buffer_read_data", bufferID as double, length as double, ret as ptr
The full code I'm using is here;
'Code to work with sockets. Example is a client.
global socketID, bufferID, data$
open "http_dll_2_3.dll" for dll as #sk
'First, create a buffer. calldll #sk, "buffer_create", ret as double bufferID = ret
'Then a socket. calldll #sk, "socket_create", ret as double socketID = ret
'Connect the socket to 127.0.0.1, port 12840 calldll #sk, "socket_connect", socketID as double, "127.0.0.1" as ptr, 10002 as double, ret as double
while VAL(data$)=0 'Continuously read and display what is sent over the socket, then echo it to the server.
'Read everything the socket has to offer into the buffer
calldll #sk, "socket_read_message", socketID as double, bufferID as double, ret as double
'Read the length of the buffer calldll #sk, "buffer_get_length", bufferID as double, ret as double length = ret print "length:"; length
'Read the buffer calldll #sk, "buffer_read_data", bufferID as double, length as double, ret as ptr data$ = winstring$(ret) print "data$"; data$
wend
'We're done so close the socket and buffer calldll #sk, "socket_destroy", socketID as double calldll #sk, "buffer_destroy", bufferID as double
close #sk
|
|
|
Post by Rod on Feb 1, 2020 7:57:55 GMT -5
If it is a string you are receiving should you not be using
"buffer_to_string(id) : Returns the contents of a buffer as a string. This is not binary-safe, the string will end at the first NULL byte."
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Feb 1, 2020 9:01:54 GMT -5
I did think that, but it doesn't work with either use.
It continues to hang at the same place.
PTR is correct for any string length?
|
|
|
Post by Rod on Feb 1, 2020 9:35:30 GMT -5
Yes the pointer is just a handle to a memory location. I am not sure why the pointer is typed as double. I would have thought long was more appropriate. I am not at home and don't have access to my API book. Ntech might contribute.
|
|