fbNetwork - OOP networking

User projects written in or related to FreeBASIC.
Posts: 41
Joined: Apr 09, 2015 20:49

fbNetwork - OOP networking

Postby StringEpsilon » Jan 12, 2019 21:01


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.


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

      "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)

If you got any feedback, bugs or patches, I'd really appreciate it. But keep in mind that I might not be fast to respond to windows specific bugs.

Ideas for sane error handling are also very welcome.
Posts: 629
Joined: May 05, 2015 5:35
Location: Germany

Re: fbNetwork - OOP networking

Postby grindstone » Jan 13, 2019 15:01

Runtime error "Procedure entry point "inet_ntop" in "WS2_32.dll" wasn't found"

WinXP 32bit / FB 1.05 here.
Posts: 41
Joined: Apr 09, 2015 20:49

Re: fbNetwork - OOP networking

Postby StringEpsilon » Jan 13, 2019 15:45

Seems like ntop is only available in Vista and later.

https://msdn.microsoft.com/de-de/librar ... 43(v=vs.85).aspx

I'm not sure I want to work around that restriction, as XP is out of support since April of 2014. But I'll add a note in the readme.

Return to “Projects”

Who is online

Users browsing this forum: No registered users and 2 guests