webserver ( sort of )

Started by
10 comments, last by logout 20 years, 9 months ago
i want to be able to connect to my gameserver and check the status of it with a http browser ( im my case IE ) i have read a lot of info on the protocol and so on but just cant get it to work. I wont be posting any code here because its ugly and its FUBAR. So i wonderd if anyone could come up with a pice off code that lets IE connect to it and send this page back to IE

<HTML>
<BODY>
<p>Hallo World</p>
</body>
</html>
plz help me .. i just cant get this to work ( been trying for 3weeks now .. and it just wont work ! ) *my gameserver is working with socket.. so i know sockets ok : only this html protocol thing is killing me !* help plz !
Advertisement
Why not let some already existing software do the job and only generate an html file?

By creating your own, you are inherently creating security issues so by using one that is already existant, you lessen your problems on the security and coding part.

ZixThree
Is your gameserver on a ISS system? If so you could link browser to an .asp and let it talk to the gameserver process and spew HTML to the browser.

-solo (my site)
-solo (my site)
The server in running on a comp in my friends house althu it is mine comp..

its not suposed to be a real webserver its just so i can type

http://181.243.15.18/ or whatever his ip is in IE

and connect and get a page back giving general info [NONE RISK INFO]
*incase i dint make the point clear: the gameserver is for a game i have made*

+ it is so i can learn this stuff ( i have tryed and failed a lot of times, now i want to see how it can be done ! )


[edited by - LogouT on July 3, 2003 6:05:49 PM]
Many existing mud codebases have that built into them. Many of them are open source, so you can take a look there.

I know that you''re not trying to write a mud or anything, but that it is the same concept.

Michael Bartman
CEO, Lead Programmer
Dark Omen Studios
http://www.darkomenstudios.com/
Michael BartmanCEO, Lead ProgrammerDark Omen Studios
well i have but i ( me aint that good a programer )

dont understand all the code + they have wrapped it up in a load of class's and so on ..

why cant anybody just write the code that i ask for ?

it wouldnt take any time at all ...

but ofc since it looks like thats what i have to do..

any links ?

[edited by - LogouT on July 3, 2003 6:35:20 PM]
*bump*
You need to post more info.

Odds are you aren''t properly sending HTTP headers, usually web servers will give an internal error when you don''t send the HTTP header correctly. For you simple page:


Content-type: text/html\r\n\r\n

Int.
Here''s what you need to do:

1) create a socket with "socket()" -- it needs to be an INET, STREAM, TCP socket.

2) bind the socket to port 80 on any local address using INADDR_ANY and port 80 (remember htons() !)

3) start listening with listen()

4) select() on the bound socket every so often to see if a connection is coming in

5) if a connection is coming in, call accept() which returns a new socket (the old socket is still listening)

6) read headers and request from this socket using recv(). Note that headers are a number of non-blank lines terminated by a blank line; then the request is a single line.

7) parse the request, and generate the data

8) write headers, followed by a blank line, followed by the response data, using send()

9) close the socket using closesocket() (WinSock) or close() (UNIX)

The headers you have to write in 8 include the status of the request (typically 200 Ok) and the headers "content-type: text/html", "content-length: %d", "cache-control: no-cache" and "connection: close".

For more information on WinSock/sockets, see your local man page or sockets programming tutorial. For more about the HTTP protocol, see the WWWC web page (www.w3c.org).

You could also try the SDL_websrv library

http://jonatkins.org/SDL_websrv/

This topic is closed to new replies.

Advertisement