[S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
D.J.Peters
Posts: 7692
Joined: May 28, 2005 3:28

[S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby D.J.Peters » Mar 26, 2015 19:51

(idea comes from: Allegro Simplificator C++ wrapper)

Simple Network Connection

download: SimpleNetworkConnection.zip Sun Mar 20, 2016

NOTE: Your FreeBASIC include files must be uptodate.

Client:
var Client = NetworkClient(address,port)
(address can be "domain.xyz" or IP "xxx.xxx.xxx.xxx")

Server:
var Server = NetworkServer(port)

Connections:
var ServerConnection = Client.GetConnection()
var ClientConnection* = Server.GetConnection()
(*)if a new client connected otherwise NULL.

send any data:
if Conection->CanPut() then
status = Connection->PutData(pBuffer,BufferSize)
end if

receive any data:
if Conection->CanGet() then
status = Connection->GetData(pBuffer [,maxSize])
end if

!!! pBuffer from connection->GetData() are allocate by "snc.bi" you have to free it with deallocate(pBuffer) !!!

status= 0 Server/Client Disconnected
status=-1 PutData/GetData Error
status> 0 nBytes sended or received

If something goes wrong you can check the ErrorCode.

ErrorCode = Client.GetLastError()
ErrorCode = Server.GetLastError()
ErrorCode = Connection->GetLastError()
if ErrorCode then print GetNetworkErrorText(ErrorCode)

That's all no more and nor less.

Joshy
Last edited by D.J.Peters on Apr 01, 2018 23:51, edited 30 times in total.
D.J.Peters
Posts: 7692
Joined: May 28, 2005 3:28

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby D.J.Peters » Mar 26, 2015 19:54

First Tests:
sncDownloadAudio.bas

sncDownloadHTMLSite.bas

sncDownloadImage.bas

sncDownloadTXTFile.bas

sncDownloadXMLDocument.bas

sncGetWANIPfromPHPScript.bas

sncGetGoogleMaps.bas
Last edited by D.J.Peters on Nov 14, 2015 23:57, edited 4 times in total.
super_castle
Posts: 289
Joined: Oct 10, 2006 7:19

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby super_castle » Mar 28, 2015 8:36

Here is the error:
D:\FreeBASIC\pebi-bas\snc.bi(306) error 18: Element not defined, S_un in 'addr.sin_addr.S_un.s_addr = INADDR_ANY'

from

WSAStartup(WINSOCK_VERSION, @wd)

greeting
D.J.Peters
Posts: 7692
Joined: May 28, 2005 3:28

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby D.J.Peters » Mar 28, 2015 10:17

super_castle wrote:D:\FreeBASIC\pebi-bas\snc.bi(306) error 18: Element not defined, S_un in 'addr.sin_addr.S_un.s_addr = INADDR_ANY'
D.J.Peters wrote:You need the newest include files they are included in latest FreeBASIC Git build.
Currently there are one compatibility issue in constructor NetworkServer. (should be fixed soon)

Code: Select all

constructor NetworkServer(byval port as ushort,byval maxConnections as integer)
  base()
  ...
  #ifdef __FB_LINUX__
  addr.sin_addr.s_addr = INADDR_ANY
  #else
  addr.sin_addr.S_un.s_addr = INADDR_ANY
  #endif
  ...
end constructor
super_castle
Posts: 289
Joined: Oct 10, 2006 7:19

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby super_castle » Mar 28, 2015 11:35

hello,thanks.

greeting
super_castle
Posts: 289
Joined: Oct 10, 2006 7:19

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby super_castle » Mar 28, 2015 12:03

not function with new include files usw....

greeting
D.J.Peters
Posts: 7692
Joined: May 28, 2005 3:28

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby D.J.Peters » Mar 28, 2015 12:19

super_castle wrote:not function with new include files usw....
give me more infos please ?

With the latest GIT builds all works here.

Joshy
super_castle
Posts: 289
Joined: Oct 10, 2006 7:19

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby super_castle » Mar 28, 2015 14:46

three programs, three error :

D:\FreeBASIC\fbc -s gui "sncDownloadAudio.bas"
D:\FreeBASIC\free-prog\SimpleNetworkConnection\snc.bi(74) error 41: Variable not declared, WINSOCK_VERSION in 'WSAStartup(WINSOCK_VERSION, @wd)'
D:\FreeBASIC\free-prog\SimpleNetworkConnection\snc.bi(310) error 18: Element not defined, S_un in 'addr.sin_addr.S_un.s_addr = INADDR_ANY'

D:\FreeBASIC\fbc -s gui "sncDownloadImage.bas"
D:\FreeBASIC\free-prog\SimpleNetworkConnection\snc.bi(74) error 41: Variable not declared, WINSOCK_VERSION in 'WSAStartup(WINSOCK_VERSION, @wd)'
D:\FreeBASIC\free-prog\SimpleNetworkConnection\snc.bi(310) error 18: Element not defined, S_un in 'addr.sin_addr.S_un.s_addr = INADDR_ANY'

D:\FreeBASIC\fbc -s gui "sncGetWANIPfromPHPScript.bas"
D:\FreeBASIC\free-prog\SimpleNetworkConnection\snc.bi(74) error 41: Variable not declared, WINSOCK_VERSION in 'WSAStartup(WINSOCK_VERSION, @wd)'
D:\FreeBASIC\free-prog\SimpleNetworkConnection\snc.bi(310) error 18: Element not defined, S_un in 'addr.sin_addr.S_un.s_addr = INADDR_ANY'

greeting
D.J.Peters
Posts: 7692
Joined: May 28, 2005 3:28

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby D.J.Peters » Mar 28, 2015 14:55

#define WINSOCK_VERSION MAKEWORD(2, 2)

It's defined in FreeBASIC/inc/win/winsock2.bi

First downlad the compiler from GIT build.
http://users.freebasic-portal.de/stw/builds/

than get the lastest include files from here:
https://sourceforge.net/projects/fbc/fi ... Builds/the latest include files

Joshy
super_castle
Posts: 289
Joined: Oct 10, 2006 7:19

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby super_castle » Mar 29, 2015 13:47

Hi, I can not find the correct files.
Can you please show exactly once?

Thank You.
greeting
super_castle
Posts: 289
Joined: Oct 10, 2006 7:19

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby super_castle » Apr 01, 2015 12:20

Hello, this error from :
https://sourceforge.net/projects/fbc/fi ... %20Builds/


----------------------------------------------------------
:\FreeBasic1\fbc -s gui "sncDownloadImage.bas"
D:\FreeBasic1\SimpleNetworkConnection\snc.bi(144) error 72: Array access, index expected, found '[' in 'FD_SET_(sock, @write_fds)'
Aborting due to runtime error 12 ("segmentation violation" signal)
Build error(s)
-----------------------------------------------------------
D.J.Peters
Posts: 7692
Joined: May 28, 2005 3:28

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby D.J.Peters » Apr 06, 2015 19:42

@super_castle I tested Simple Network Connection with FreeBASIC 1.02 successfull.

Joshy
super_castle
Posts: 289
Joined: Oct 10, 2006 7:19

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby super_castle » Apr 07, 2015 11:13

Hello, with FreeBASIC 1.02 its ok.

Thanks.
D.J.Peters
Posts: 7692
Joined: May 28, 2005 3:28

Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.

Postby D.J.Peters » Apr 25, 2015 17:59

added: "snc_utility.bi"

Joshy

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 0 guests