help me! problem with receiving
please help!!
Hey,first of all i guess my question will be simple for most of you,but take it easy i am just a newcomer ok?
Here is the problem:
I have a server program which accepts one of the strings "e","w","n","s" and returns "+" or "-" depending on the situation.And i am trying to write a client program which
communicates with the string.I write the code below for testing:
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
int main(int argc,char *argv[])
{
char *dest_ip;
char *dest_port;
int sockfd;
struct sockaddr_in dest_addr;
int test1,test2,test3;
dest_ip = argv[1];
dest_port = argv[2];
/*NETWORK CONNECTIONS*/
sockfd = socket(AF_INET, SOCK_STREAM, 0);
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = htons(atoi(dest_port));
dest_addr.sin_addr.s_addr = inet_addr(dest_ip);
memset(&(dest_addr.sin_zero), ''\0'', 8);
test 1 = connect(sockfd, (struct sockaddr *)&dest_addr, sizeof(struct sockaddr));
char *msgs = "s";
char *msgr;
int len =strlen(msgs);
test2 = send(sockfd,msgs,len,0);
test3 = recv(sockfd,msgr,len,0);
printf("%d %d %d",test1,test2,test3);
return 0;
}
In normal cases i guess i should see 0 1 1 on the screen but
i see 0 1 0 how hard i tried!I can''t receive response from the
server,what might be the possible problem?Please help me cause
it''s soooooo important.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement