Hi.
Here is my code:
In one terminal:
And in another one:
What's wrong with this code?
Here is my code:
Code:
int
main(int argc, char *argv[])
{
int sockfd;
unsigned short port = 1234;
char *address = "127.0.0.1";
char message[BUFSIZ];
struct sockaddr_in connection;
if( (sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
printf("socket error\n");
exit(EXIT_FAILURE);
}
connection.sin_addr.s_addr = inet_addr(address);
connection.sin_port = htons(port);
connection.sin_family = AF_INET;
memset( &(connection.sin_zero), '\0', 8 );
if( (connect(sockfd, (struct sockaddr*)&connection, sizeof(struct sockaddr))) == -1);
{
printf("connect error\n");
exit(EXIT_FAILURE);
}
for(;;)
{
scanf("%s", &message);
send(sockfd, message, sizeof(message), 0);
}
close(sockfd);
return 0;
}
In one terminal:
nc -k -l 127.0.0.1 1234
And in another one:
Code:
[CMD]./a.out[/CMD]
connect error
What's wrong with this code?