Topic : BSD Sockets
Author : Unknown
Page : << Previous 7  
Go to page :


appropriate
      (System V vs BSD). */

   bcopy ( hp -> h_addr_list[0], &myname.sin_addr.s_addr,
           hp -> h_length );
   /* memcpy ( &myname.sin_addr.s_addr, hp -> h_addr_list[0],
           hp -> h_length ); */
      
   /* More debug code: Verify the contents of structure myname
      prior to trying to connect to the (remote) server.    */

   printf("\nInformation provided in client's");
   printf(" connect request\n");
   printf("\tRemote host address is %lx\n",
        ntohl ( myname.sin_addr.s_addr ) );
   printf("\tPort number supplied is %d\n",
        ntohs ( myname.sin_port ) );
   printf("\tInternet family ID is %d\n", myname.sin_family);
   printf("\tsin_zero character string is: %s\n",
        myname.sin_zero);

   /* Establish socket connection with (remote) server.  */

   if ( ( connect ( sock, &myname, sizeof(myname) ) ) < 0 ) {
         printf("network client %s connect failure %d\n",
              argv[0], errno);
         perror("network client");
         close (sock);
         exit(4);
      }

   /*  Exchange data with client.  Clear buffer bytes first. */

   /* Take your pick, depending on your system's pedigree.  The
      System V function has not been tested. */

   bzero  ( buf,    sizeof( buf) );  /* zero buffer, BSD. */
   /* memset ( buf, 0, sizeof( buf) ); /* zero buffer S5. */

   strcpy ( buf, "Message from client to server" );
   write ( sock, buf, sizeof(buf) );

   /* Now read message sent back by server.    */

   if ( ( cnt = read (sock, buf, sizeof(buf) ) ) < 0 ) {
      printf("network client socket read failure &d\n", errno);
      perror("network client");
      close(sock);
      exit(5);
   }
   else
   printf("network client received the message %s\n", buf);

   /* Now send a message with 0 bytes. */

   bzero  ( buf,    sizeof( buf) );  /* zero buffer, BSD. */
   /* memset ( buf, 0, sizeof( buf) ); /* zero buffer S5. */
   write ( sock, buf, 0 );
   close (sock);
   exit(0);

}  /* end of main procedure */

Page : << Previous 7