Hello, and to whom it may concern,
I want to write a freebasic program that can listen on an arbitrary port and respond to the url sent on that port with a dynamically rendered page. I'm pretty comfortable with the actual programming, but I'm not sure how to get freebasic to listen to the web.
Any pointers to the right page in the manual would be just fine, or suggestions on how to do this would be lovely.
I want to write a program that listens on a http port and can send a webpage back
Re: I want to write a program that listens on a http port and can send a webpage back
I'm sure there are nicer wrappers or libraries for this somewhere on the forum that someone else will recommend, but at the most basic its the same as C. For a server, you use the functions
socket
bind
listen
accept
recv
send
shutdown
close(socket)
Those 8* are pretty much all you need and the same whether you're Windows-y or Linux-y, or something-else-y. Which include files you need for them does change depending on what platform you're building on.
A Windows tutorial for a simple client/server in C starts here. Implementing actual HTTP over that is just a matter of reading the requests, then sending out properly formatted responses. HTTPS is more complicated.
* Well, Windows requires an extra one, WSAStartup, before you do any of those
socket
bind
listen
accept
recv
send
shutdown
close(socket)
Those 8* are pretty much all you need and the same whether you're Windows-y or Linux-y, or something-else-y. Which include files you need for them does change depending on what platform you're building on.
A Windows tutorial for a simple client/server in C starts here. Implementing actual HTTP over that is just a matter of reading the requests, then sending out properly formatted responses. HTTPS is more complicated.
* Well, Windows requires an extra one, WSAStartup, before you do any of those
Re: I want to write a program that listens on a http port and can send a webpage back
https://wiki.gnome.org/Projects/libsoup
As I said, FB should already be able to interface with it using GObject Introspection. But examples for GTK3 with GIR are lacking last I checked.
EDIT: actually I can't find any GIR header files in FB. I swear I saw them once. They eliminate the need to port each gtk header file individually.
Re: I want to write a program that listens on a http port and can send a webpage back
Maybe this could help:
viewtopic.php?t=4199&hilit=Simple+Web+Server&start=15
The modified code by 'cha0s' works rather well.
Tested on windows 7 with
Note no ssl support or only http:// no https://
Bye the bye a really small webserver for window is:
https://en.wikipedia.org/wiki/Xitami
https://imatix-legacy.github.io/xitami.com/
Also no native ssl support...
viewtopic.php?t=4199&hilit=Simple+Web+Server&start=15
The modified code by 'cha0s' works rather well.
Tested on windows 7 with
Code: Select all
Const WM_SHELLNOTIFY = WM_USER + 5
Const ID_RUN = 1001
Const ID_PAUSE = 1002
Const ID_EXIT = 1003
Const SERVER_ADDR = "127.0.0.1"
Const HOMEDIR = "wwwroot"
Const DEFAULT_PORT = 80
Const SERVER_BUFFSIZE = 16
Bye the bye a really small webserver for window is:
https://en.wikipedia.org/wiki/Xitami
https://imatix-legacy.github.io/xitami.com/
Also no native ssl support...
Re: I want to write a program that listens on a http port and can send a webpage back
This is probably enough that I can come up with something from this. Thanks!
Re: I want to write a program that listens on a http port and can send a webpage back
Perhaps you'll find your needs in the NetToBac solution, a library with BASIC-like syntax. nOPEN and nCLOSE a network connection like a file on the disk and nGET or nPUT data over the socket. Find the docu at
https://users.freebasic-portal.de/tjf/P ... /doc/html/
Regards
https://users.freebasic-portal.de/tjf/P ... /doc/html/
Regards
Re: I want to write a program that listens on a http port and can send a webpage back
That's even better. Thank you very much.