[S]imple [N]etwork [C]onnection win and lin 32/64-bit.
-
- Posts: 8629
- Joined: May 28, 2005 3:28
- Contact:
[S]imple [N]etwork [C]onnection win and lin 32/64-bit.
(idea comes from: Allegro Simplificator C++ wrapper)
Simple Network Connection
download: SimpleNetworkConnection.zip Nov 17, 2022
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
Simple Network Connection
download: SimpleNetworkConnection.zip Nov 17, 2022
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 Nov 17, 2022 4:17, edited 34 times in total.
-
- Posts: 8629
- Joined: May 28, 2005 3:28
- Contact:
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
First Tests:
sncDownloadAudio.bas
sncDownloadHTMLSite.bas
sncDownloadImage.bas
sncDownloadTXTFile.bas
sncDownloadXMLDocument.bas
sncGetWANIPfromPHPScript.bas
sncGetGoogleMaps.bas
server.bas
client.bas
I added simple server and client.
sncDownloadAudio.bas
sncDownloadHTMLSite.bas
sncDownloadImage.bas
sncDownloadTXTFile.bas
sncDownloadXMLDocument.bas
sncGetWANIPfromPHPScript.bas
sncGetGoogleMaps.bas
server.bas
client.bas
I added simple server and client.
Last edited by D.J.Peters on Sep 09, 2020 14:05, edited 5 times in total.
-
- Posts: 289
- Joined: Oct 10, 2006 7:19
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
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:\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
-
- Posts: 8629
- Joined: May 28, 2005 3:28
- Contact:
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
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
-
- Posts: 289
- Joined: Oct 10, 2006 7:19
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
hello,thanks.
greeting
greeting
-
- Posts: 289
- Joined: Oct 10, 2006 7:19
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
not function with new include files usw....
greeting
greeting
-
- Posts: 8629
- Joined: May 28, 2005 3:28
- Contact:
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
give me more infos please ?super_castle wrote:not function with new include files usw....
With the latest GIT builds all works here.
Joshy
-
- Posts: 289
- Joined: Oct 10, 2006 7:19
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
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:\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
-
- Posts: 8629
- Joined: May 28, 2005 3:28
- Contact:
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
#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
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
-
- Posts: 289
- Joined: Oct 10, 2006 7:19
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
Hi, I can not find the correct files.
Can you please show exactly once?
Thank You.
greeting
Can you please show exactly once?
Thank You.
greeting
-
- Posts: 8629
- Joined: May 28, 2005 3:28
- Contact:
-
- Posts: 289
- Joined: Oct 10, 2006 7:19
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
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)
-----------------------------------------------------------
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)
-----------------------------------------------------------
-
- Posts: 8629
- Joined: May 28, 2005 3:28
- Contact:
-
- Posts: 289
- Joined: Oct 10, 2006 7:19
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
Hello, with FreeBASIC 1.02 its ok.
Thanks.
Thanks.
-
- Posts: 8629
- Joined: May 28, 2005 3:28
- Contact:
Re: [S]imple [N]etwork [C]onnection win and lin 32/64-bit.
added: "snc_utility.bi"
Joshy
Joshy