Tasp
Full Member
Posts: 215
|
Post by Tasp on May 8, 2020 11:56:35 GMT -5
Is the LBnet.dll capable of using TCP comms? It works UDP without any issues. But have now moved onto requiring TCP connections instead. DLL can be found here for those that need a UDP version, LBNet on Github
|
|
|
Post by Chris Iverson on May 8, 2020 14:16:28 GMT -5
Yeah, the same DLL can do TCP and TLS as well. Most of the code is fairly similar for doing TCP. Just take UDP out of the function name, and most of the UDP test code will work the same. The only ones that don't convert are UDPSendTo and UDPReceiveFrom(and UDPConnectFrom). I should make a separate file to show the wrapper functions for just TCP, though, and a full proper release. You can get the full WrapperFunctions.bas file here: github.com/iversc/lbnet/blob/master/WrapperFunctions.basWith those wrapper functions in place, here's a quick little TCP demo implementing a tiny bit of HTTP: call OpenLBNetDLL
input "press ENTER to begin.";a
connectServer$ = "www.google.com" port$ = "80" timeout = 0 hSock = Connect(connectServer$, port$, timeout) if IsSocketInvalid(hSock) then print "Connect() failed. - ";GetError() goto [doEnd] end if
print "Connect() successful."
crlf$ = chr$(13) + chr$(10) lf$ = chr$(10) request$ = "GET / HTTP/1.1" + crlf$ + _ "Host: google.com" + crlf$ + crlf$
lenRequest = len(request$) print "Send() - ";UDPSend(hSock, request$, lenRequest)
[respLoop] timer 0 print "Waiting for response..." ret = IsReadAvailable(hSock, 0)
if ret = 0 then print "Still waiting..."
timer 1000, [respLoop] wait end if
[doReceive]
bufLen = 1024 buf$ = space$(bufLen)
num = Receive(hSock, buf$, bufLen) theError = GetError()
if num = -1 then if theError = 10101 or theError = 10054 then print "Connection closed or reset by peer." else print "Socket error occurred. - ";theError end if
goto [doClose] end if
print "Response - ";left$(buf$, num)
[doClose] a = CloseSocket(hSock)
[doEnd] call CloseLBNetDLL
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on May 9, 2020 7:49:05 GMT -5
I'm sure there was a TCP Server demo code on one of your original versions/posts but cannot find it anywhere?
In the wrapper code, I dont see anything specific to TCP? Are you saying we can use UDPxxxxxx functions but it will work in a TCP enviroment?
|
|
|
Post by Chris Iverson on May 9, 2020 15:18:20 GMT -5
I think I've accidentally overwritten them when I was adding features to the DLL. I'll get a new proper example written up and included.
And I meant that the TCP versions of a lot of the functions just don't have UDP in the name.
UDPConnect/Connect, UDPCreateListenSocket/CreateListenSocket, UDPSend/Send, UDPReceive/Receive, UDPClose/CloseSocket.
|
|
|
Post by Chris Iverson on May 9, 2020 22:19:13 GMT -5
I've pushed a new change to github, adding two new files: test-tcp-client.bas and test-tcp-server.bas. Click those links to get the source code for those files. Should work fine with the already-available LBNet DLL.
|
|
|
Post by cryptomen on Mar 26, 2021 4:38:43 GMT -5
Where can I download LBNet.DLL?
|
|
|
Post by Rod on Mar 26, 2021 5:29:12 GMT -5
The first post has Chris’s link to GitHub
|
|