|
int connect(int s, struct sockaddr *server, length) |
|
|
int s; // Socket variable struct sockaddr_in server; // Network addr for server /* --------------------------- Create TCP socket --------------------------- */ s = socket( AF_INET, SOCK_STREAM, 0 ); / Create a TCP socket /* ------------------------------------ Setup the server's Network Address ------------------------------------ */ server.sin_family = AF_INET; server.sin_addr.s_addr = htonl(SrvIP-address); server.sin_port = htons(SrvPortNumber); /* --------------------------------------------------------- Make a connection request to the server (The server must be in an accept() call to be successful) --------------------------------------------------------- */ if ( connect(s, server, sizeof(struct sockaddr_in) ) == 0 ) { perror("connect: "); exit(1); } // After this, the client can use the TCP socket s to communicate // (to the data TCP port) with server // // Use: read(s, ....) to get server's replies write(s, ....) to send data to server close(s) to disconnect |