fbNetwork - OOP networking

User projects written in or related to FreeBASIC.
Post Reply
StringEpsilon
Posts: 42
Joined: Apr 09, 2015 20:49

fbNetwork - OOP networking

Post by StringEpsilon »

Hi,

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)
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.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: fbNetwork - OOP networking

Post by grindstone »

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

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

Re: fbNetwork - OOP networking

Post by StringEpsilon »

Seems like ntop is only available in Vista and later.

https://msdn.microsoft.com/de-de/librar ... s.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.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: fbNetwork - OOP networking

Post by D.J.Peters »

@grindstone S.N.C (simple network connection) should work with Windows XP through Windows 10 and all Linux devices with network connectivity.

Joshy
Post Reply