1

How can I convert the input from the client from the server to a string or some other data type. My server can print the recvline from clients but doesn't recognize it as a common data type...

void timing()
{
   for (long i = 0; i < 200000000; i ++){
      printf("");
   }
}

int main(int argc, char **argv){
  int   i;
  int sockfd;
  struct sockaddr_in    servaddr;
  char sendline[MAXLINE];
  char recvline[MAXLINE];

  time_t start, finish, final;
  start = clock();
  timing(); // a function that takes a differential time based on the client
  finish = clock();
  final = (finish - start) /  CLOCKS_PER_SEC;
  printf("timing: %ld\n", final);

  if (argc != 2){
      perror("usage: tcpcli <IPaddress>");
      exit(-1);
  }

  sockfd = socket(AF_INET, SOCK_STREAM, 0);

  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  servaddr.sin_port = htons(SERV_PORT);
  inet_pton(AF_INET, argv[1], &servaddr.sin_addr);

  connect(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr));

  char ** temp = NULL;
  char * timing = NULL;
  strtol(timing, temp, final); //***Problem here
  write(sockfd, timing, 5);
  bzero(recvline, MAXLINE);
  if (read(sockfd, recvline, MAXLINE) == 0){ //reads from server
          perror("Server terminated!");
          exit(-1);
      }

  fputs(recvline, stdout);
netcoder
  • 66,435
  • 19
  • 125
  • 142
  • 4
    It would help if you posted your code and explained from there on – loopbackbee Nov 29 '12 at 21:20
  • This is not Python, did you tag it by mistake? – Burhan Khalid Nov 30 '12 at 02:28
  • Can you post your python code, not your c code? – Alan Nov 30 '12 at 03:05
  • The strtol line does not make any sense to me - you are passing it a NULL string pointer as input which it wil try to dereference, probably generating segfault/AV. Also, why are you trying to pass a time_t as the base for conversion? Result is dumped anyway. What are you trying to do, communicate the time_t final as a a string? A sprintf() call would make a bit more sense to me? – Martin James Nov 30 '12 at 07:00

0 Answers0