In either case you need to call create() to allocate a socket, and close() (or closesocket(), not sure which it is offhand) to free it.
For a client socket, you want to connect to an address. Thats what the connect() function does.
For a server socket, its slightly more complex. First of all, you bind() to an address (port really), to tell the OS that anything comming in on this port, send to me (connect() does this automatically). Then you call listen(). listen() tells the OS that other people can connect to your computer on the port it was bind()ed to.
Then, you call accept() to accept a new connection. The accept() function blocks until a connection arrives, so you need to use it in a thread, use WSAAccept() (evil evil evil), or call select() to see if theres connections waiting (select() just checks the status of a socket and returns immediately).
After you''ve accept()ed, you get a new socket. This socket is the connection to the other computer. You use it to send or recieve data.
So, the client creates the socket and then connect()s, and the server creates a listening socket and then accept()s another new socket.
So, a client program will usually have 1 socket - the one that connects to the server, whereas a server program will have 1 socket listening for connections, and then additional 1 socket for every connected user.
If you want yet another socket class to look at, you can get my one from
Here. It uses select(), and compiles and runs fine under windows and linux (red hat 8 and 9).