recv command in sock in c
i have a http client and server which must interact with each other using GET command. My client is working fine. But I am having problem with the server one.
Code:
#include <sys/socket.h> Any idea what s wrong with Code:
re=recv(accept_connection,command,strlen(command),0); |
i put a perror in there and got:
Code:
value of accept command =4 Code:
cout << "value of accept command ="<<accept_connection<< endl; |
easy,
Code:
char *command="GET /index.jsp HTTP/1.0\n\n"; make it a proper buffer Code:
#define SZ 512 Code:
value of accept command =4 Code:
$ nc -vv localhost 8070 |
thanks for help.
I am having another problem now. Now recv function returns 1 which means it can receive message from client, but it receives only one character of the client message. I added MSG_WAITALL as the last parameter in recv function. Then I used strcpy to compy the message from the client, but it returned only the first letter. Then I tried to define a single counter and used a loop to receive the message from client and used strcat to store the whole message in a char variable. This worked for me but it returned some extra characters; however, I don't want to define a fixed variable for this loop, since different client may send messages in different lenghts. Here is the code: Code:
cout << "value of accept command ="<<accept_connection<< endl; |
funny, cos as i posted I was getting everything.
maybe it's a client problem? did you try it using my netcat example as the client. you should learn to use netcat, it's indispensable for this work. it can serve as an adhoc client or server, great for testing. |
I forgot about that part already, because it is less important from my new problem.
Now I suppose that client has sent the correct command, so my server is ready to send content of a text file to my client. Code:
cout << line1 << endl; |
what exactly are you doing?
why http? do you know how http works? the construction of the header etc.? try this: Code:
printf "HTTP/1.1\nContent-Length:6\nContent Type: text/html\n\nhELLO\n" | nc -lp 50125 |
All times are GMT -5. The time now is 11:31 PM. |