Create a connection with connection oriented sockets

  1. Call socket() on srvr PCO with the following parameters: domain, SOCK_STREAM, proto. Created socket is referred as srvr_s below;

  2. If srvr_wild is true, fill in network address part of srvr_bind_addr with wildcard network address;

  3. Copy port part of srvr_addr to port part of srvr_bind_addr address;

  4. Bind srvr_s socket to srvr_bind_addr address.

  5. If port part of srvr_addr is zero (not specified), then call getsockname() on srvr_s socket to obtain the assigned port and set it to the port part of srvr_addr.

  6. Call listen() for srvr_s socket with default backlog.

SOCK_STREAM

  1. Call socket() on clnt PCO with the following parameters: domain, SOCK_STREAM, proto. Created socket is referred as clnt_s below.

  2. If clnt_addr is not equal to NULL, bind() clnt_s socket to clnt_addr address.

  3. Initiate accept() for srvr_s socket;

  4. Call connect() to connect client socket clnt_s to server with srvr_addr address;

  5. Wait for accept() completion to get accepted_s socket;

  6. Close srvr_s socket

  7. Set accepted_s to srvr_s variable.

Parameters:

srvr

PCO for server

clnt

PCO for client

domain

Domain used in the connection

proto

Protocol used in the connection

srvr_addr

server address (cannot be NULL) to be used as a template for bind() on server side and for connect() on client side. Network address part of the srvr_addr must be specified, but it is allowed to left port part of srvr_addr unspecified, which means we do not mind which address the server is bound to (on return the actual port used in established connection is set to the port part of srvr_addr).

srvr_wild

bind server to wildcard address or not (although we must specify network address in srvr_addr parameter, it is still allowed to bind server socket to the wildcard address)

clnt_addr

address to bind client to or NULL

srvr_s

SOCK_STREAM socket reside on srvr

clnt_s

SOCK_STREAM socket reside on clnt