Advertisement

Question about telnet and winsock.

Started by September 24, 2006 11:54 AM
5 comments, last by Jabus10 18 years, 4 months ago
I'm very new to network programming so I decide to do a basic task. I am basically trying to replicate telnet. When you open telnet and connect to www.microsoft.com on port 80 and then type: GET / HTTP/1.1 Host: www.microsoft.com you get the html code for the index.html page on microsoft.com However i connect o microsoft .com on port 80 and then use

char buffer[256];
ZeroMemory(buffer,256);
strcpy(buffer,"GET / HTTP/1.1 Host:www.thebuggychatroom.info");
int r;
r=send(s,buffer,256,0);
when i use the recv function i get nothing in the recieving buffer. it remains empty. I just wondered if anyone could point me in the right direction.
Telnet is another protocol. You opened a telnet session to a HTTP server. Typicaly telnet is just a very thin layer over a raw TCP socket. The main difference between HTTP and a telnet connection is a telnet connection maintains bi-directonal communication, where as a HTTP session is simply a request then reply.

Think of it this way... telnet is a open conversation. HTTP is a question then answer.

Check out RFC 854


edit...

Are you trying to replicate a Telnet server or client?
∫Mc
Advertisement
Acctaully, I think you forgot the newlines...
try this:

strcpy(buffer,"GET / HTTP/1.1\r\nHost:www.thebuggychatroom.info\r\n");

EDIT:
removed space from string that would probably prevent it from working
No, the problem is that you send() 256 bytes, not the actual size of the request.

Remember to end the header with two pairs of \r\n.
enum Bool { True, False, FileNotFound };
I'm sorry if i'm being really stupid here but the number of bytes to send would be the same as the number of chars in the array i.e. 52 (including the \r\n)
There are two sets of \r\n required if I'm not mistaken.
Advertisement
Thank you. I now realise that their are 2 pairs or \r\n but is the amount of bytes i send the same as the number of chars in the array.

This topic is closed to new replies.

Advertisement