It's still very early, but the basic client works now. And I really need people to test it and give me some feedback on how it feels to use it.
It supports:
* TCP and UDP
* Windows and Linux
* IPv4 and IPv6
fbNetwork on GitHub - MPL 2.0 as usual.
Motivation (from the readme)
Since you can't get a pointer to a method of a UDT / class instance, working with callback based network libraries can be a bit of a hassle when the rest of your programm is OOP. This library aims to fix that pain by implementing the network part itself in a class so the programmer can simply extend it to implement their parsing, event handling and so on on top.
A very simple HTTP client can be found in the examples folder.
Example:
Code: Select all
#include once "../src/fbNetworkClient.bas"
const NEWLINE = !"\r\n"
type httpClient extends fbNetworkClient
declare sub onConnect()
declare sub onClose()
declare sub onError(errorCode as fbNetworkError)
declare sub onMessage(message as string)
end type
sub httpClient.onConnect()
dim request as string
this.sendData(_
"GET / " + "HTTP/1.1" + NEWLINE + "Host: httpstat.us " + NEWLINE + _
"Connection: close" + NEWLINE + "User-Agent: GetHTTP 0.0" + NEWLINE + NEWLINE )
print "Connected to "& this.host & ":" & this.port
end sub
sub httpClient.onClose()
end sub
sub httpClient.onError(errorCode as fbNetworkError)
end sub
sub httpClient.onMessage(message as string)
print "Got data: ";
print trim(right(message, len(message) - instrRev(message, NEWLINE)-1),any NEWLINE)
end sub
dim client as httpClient
print "Testing ipv4.icanhazip.com"
client.open("ipv4.icanhazip.com", 80)
Ideas for sane error handling are also very welcome.