title: berkeley sockets, running simple client and server connecting
body: <p>I'm just starting out on networking programming in c. I followed a simple tutorial to create a server which accepts a connection and prints out the message sent from the client.</p>
  
  <p>the client takes an argument as the address of the server.</p>
  
  <p>I'm not sure how to specify the address of the server? Is it my machine name?</p>
  
  <p>I'm running the server in one terminal and trying to connect from another. Thanks for any help :)</p>
  
  <p>here's the server code</p>
  
  <pre><code>   `#include &lt;sys/types.h&gt;
      #include &lt;sys/socket.h&gt;
      #include &lt;netinet/in.h&gt;
      #include &lt;arpa/inet.h&gt;
      #include&lt;stdio.h&gt;
      #include &lt;errno.h&gt;
      #include &lt;stdlib.h&gt;
      #include &lt;string.h&gt;
      #include &lt;unistd.h&gt;
  
      int main(int argc, char *argv[])
      {
      #define BUFLEN 1500
      int fd;
      ssize_t i;
      ssize_t rcount;
      char buf[BUFLEN];
  
      printf("test1");
      fd = socket (AF_INET,SOCK_STREAM,0);
      if (fd == -1){
           printf("Oh dear, something went wrong with read()! %s\n", strerror(errno));
      }
  
      struct sockaddr_in addr;
  
      addr.sin_addr.s_addr = INADDR_ANY;
      addr.sin_family = AF_INET;
      addr.sin_port = htons(500);
  
      if (bind(fd, (struct sockaddr *)&amp;addr, sizeof(addr)) == -1) {
          printf("cannot bind socket");
      }
  
      if (listen(fd, 20) == -1) {
         printf("unable to listen");
      }
  
      int connfd; 
      struct sockaddr_in cliaddr; 
      socklen_t   cliaddrlen = sizeof(cliaddr);
  
  
      connfd = accept(fd, (struct sockaddr *) &amp;cliaddr, &amp;cliaddrlen);
      if (connfd == -1) {
          printf("unable to accept");
      }
  
  
  
  
      rcount = read(fd, buf, BUFLEN);
      if (rcount == -1) {
  
      // Error has occurred
      }
      for (i = 0; i &lt; rcount; i++) { 
          printf("%c", buf[i]);
      }
  
      }`
  </code></pre>