Click here to Skip to main content
15,888,323 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello guys, i'm having this project where i must create a server that communicates with a browser.I must write something like this in the browser: http://localhost:11880/path
and the message printed in the server will be:

GET /path HTTP/1.1
Host: localhost:11880
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.12)
Gecko/20101027 Ubuntu/10.04 (lucid) Firefox/3.6.12
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 115
Connection: keep-alive
Referer: http://localhost:11880/path

Firstly i haven't understand what 'get' will do. The printed message will be different for get and post method, but i cant understand if i will have to write: 'get http://localhost:11880/path' in the browser or just 'http://localhost:11880/path' and get will be printed to server through the request. Additionaly i have to send back to the browser a RFC response, but there are so many cases and i don't know in which case to print each message(404: not found, 501 Not implemented etc) and how to print it. Every help would be appreciated, i am desperate, i have stuck at this point for about a day.
Posted
Comments
pasztorpisti 22-Dec-13 23:23pm    
You could use wireshark to capture the sent messages between your "server app" and the browser. It has a "Follow TCP Stream" functionality that would give you extremely helpful info to understand whats going on.
Mohibur Rashid 23-Dec-13 7:40am    
livehttp also a good choice for firefox
pasztorpisti 23-Dec-13 8:45am    
Sure, its comfortable and good idea to use a browser plugin like livehttp or firebug.

1 solution

The input you have provided will be generated by browser.

http://localhost:11880/path

the above line means; that your browser will connect with your server with port 11880. So, your server will have to response to port 11880

There are four request perform by web server

1. GET
2. POST
3. DELETE //in general disabled for security purpose
4. HEADER //in case of header response server reply with only header no data.

As a starter you think only about message 200 and 404.

200=if the file is available
404=if the requested file is not available

here is an example of http response on a requst:

HTTP/1.1 200 OK
Date: Sun, 22 Dec 2013 23:55:12 GMT
Server: Apache
X-Powered-By: PHP/5.3.27
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/javascript

two important response is
line 1: that will say file status:
line 11: that will tell the browser about the type of replied data.
just make this two:
C++
HTTP/1.1 200 OK\r\n
Content-Type: text/javascript\r\n


after these two two new line must have to be added "\r\n"; the other new line is at the end of content-type statement


then finally print rest of the file content.

Finally don't panic
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900