When i run this, I get no compilation problems, When I try sending the first string it sends ok, but when I try to send the second string i get this error: Command unrecognized "***"
Input: helo
Received: 501 5.0.0 helo requires domain address
Input: helo
Received: 500 5.5.1 Command unrecognized: "@"
Input: helo
Received: 500 5.5.1 Command unrecognized: "f@p2@W@"
500 5.5.1 Command unrecognized: "@"
Its odd because the first string sends succesfully. Does anyone have any ideas??
Thanks.
Code:
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <errno.h>
#include <arpa/inet.h>
void main(int argc, char *argv[])
{
int i = 1;
int sockfd;
printf("Connecting to %s on port %s\n", argv[1], argv[2]);
int numbytes;
int numbytes1;
char in[200];
char buf[200];
struct sockaddr_in address;
address.sin_family = AF_INET;
int vin = atoi(argv[2]);
address.sin_port = htons(vin);
// address.sin_port = inet_addr(argv[2]);
address.sin_addr.s_addr = inet_addr(argv[1]);
memset(&(address.sin_zero), '\0', 8);
sockfd = socket(AF_INET, SOCK_STREAM,0);
i= 0;
if (connect(sockfd, (struct sockaddr *)&address, sizeof(struct sockaddr))== -1)
{
printf("Couldnt connect ");
}
while (i != -1)
{
if((numbytes= recv(sockfd, buf,200-1,0))==-1)
{
printf("Error in receive");
i = -1;
}
buf[numbytes] = '\0';
printf("Received: %s",buf);
printf("\nInput: ");
strcpy(in, "\0");
scanf("%s", in);
if (send(sockfd, in, 100-1,0)== -1)
{
printf("Couldnt send");
i = -1;
}
}
close(sockfd);
}