Archived

This topic is now archived and is closed to further replies.

logout

webserver ( sort of )

Recommended Posts

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 !

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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/

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
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).

Share this post


Link to post
Share on other sites
Well it crashes when i try to get the request line...




char buffer[256];
SOCKET sk;
SOCKET cli;

CreateSocket(sk);
BindSocket(sk,80);
ListenSocket(sk, 12);

cli = AcceptSocket(sk, NULL);

if( recv(cli, buffer, 256, 0) < 1)
LError(GTHROW, "Cant get request");

//more stuff down here



and it crashes
when i run the appelication and use IE and connect to
http://localhost

and in my dos window this text appears:

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.




so i really dont get why it crashes




Share this post


Link to post
Share on other sites