web server on a other port than 80.


How can i run a web server on port 82 an this change on runtime.


The function tcp_listen tells the system to accept an incoming session from a particular port and which data handler to use for received packets. Lookup this function through the help system for more details.

Is this also for the html internet server ???
How can i set the port for “http_init()” ??


The #define value that sets the port for http is HTTP_PORT, which by default is set to 80 if not defined by the user. Simply put

#define HTTP_PORT 82

and the HTTP server will work from port 82. As far as runtime changes, this would require a small code change to the http library. Once you call http_init, there is no way to change the port without bringing the server down, so you would need to live with this requirement. You can shut down the server with http_shutdown() and modify the html.lib library to allow a global variable to be used for the port setting. Do a grep on HTTP_PORT and you will find it used in the http_handler() function within the HTTP_INIT state. It is a parameter in the call to http_sock_extlisten() and you could replace HTTP_PORT with a global variable you could then change. You would need to make sure the global variable is set to the proper port value BEFORE calling http_init().

I’m not sure if this would work for you or not, but I needed to specify the SMTP_PORT using a variable for an e-mail application. So I tried:

#define SMTP_PORT Config.SMTPPort

and it worked fine. I didn’t need to modify the library.


Janet is right, it is a macro and you could set it to the variable name, which would be much easier than editing the library. Sorry about not thinking of that. You still need to make sure you have the variable defined before initializing the server, and would still need to shutdown and re-initialize the server to make a change to that variable active as it is only referenced during the initialization of the port.