title: socket connection failure
body: <p>I am beginner in socket programming and reading Linux Network Programming book. I decided to implement client-server connection as shown in the book. Server program is run on Ubuntu 14.04 machine and client code is run from Mac machine. The server code is the following</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;string.h&gt;
  
  const char message[] = "hello, world\n";
  
  int main()
  {
    int sock = 0;
    int port = 0;
    sock = socket(AF_INET, SOCK_STREAM, 0);
  
    if (sock == -1)
      fprintf(stderr, "failed\n");
    else
      printf("connection is establisshed\n");
  
    struct sockaddr_in server;
    server.sin_family = AF_INET;
    server.sin_addr.s_addr = htonl(INADDR_ANY );
    server.sin_port = 3500;
  
    int status = bind(sock, (struct sockaddr*) &amp;server, sizeof(server));
    if (status == 0)
      printf("connection completed\n");
    else
      printf("problem is encountered\n");
  
    status = listen(sock, 5);
    if (status == 0)
      printf("app is ready to work\n");
    else
    {
      printf("connection is failed\n");
      return 0;
    }
  
    while (1)
    {
      struct sockaddr_in client = { 0 };
      int sclient = 0;
      int len = sizeof(client);
      int childSocket = accept(sock, (struct sockaddr*) &amp;client, &amp;len);
      if (childSocket == -1)
      {
        printf("cannot accept connection\n");
        close(sock);
        break;
      }
  
      write(childSocket, message, strlen(message));
  
      close(childSocket);
    }
  
    return 0;
  }
  </code></pre>
  
  <p>As for client side i wrote the following code</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;sys/types.h&gt;
  #include &lt;sys/socket.h&gt;
  #include &lt;netdb.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;arpa/inet.h&gt;
  
  int main(int argc, char* argv[])
  {
    int sock = 0;
    int port = 0;
    struct sockaddr_in servaddr;
    sock = socket(AF_INET, SOCK_STREAM, 0);
    int status = 0;
    char buffer[256] = "";
    if (sock == -1)
    {
      printf("could not establish connection\n");
      exit(1);
    }
  
    port = 3500;
    servaddr.sin_family = AF_INET;
    servaddr.sin_addr.s_addr = inet_addr(argv[1]);
    servaddr.sin_port = htons(port);
    status = connect(sock, (struct sockaddr*) &amp;servaddr, sizeof(servaddr));
    if (status == 0)
      printf("connection is established successfully\n");
    else
    {
      printf("could not run the app\n");
      exit(1);
    }
  
    status = read(sock, buffer, sizeof(buffer));
    if (status &gt; 0)
      printf("%d: %s", status, buffer);
  
    close(sock);
  
    return 0;
  }
  </code></pre>
  
  <p>To get IP address of client machine I run ifconfig from terminal an get inet_addr 192.168.1.165 value. Now when I pass that address string as command line argument I get message that app is not running message. There is problem with address that I got, as I understand. So what is the problem?
  Thanks in advance</p>