Information Technology Reference
In-Depth Information
send()
Sends data on a connected socket.
sendto()
Sends data on an unconnected socket.
recv()
Receives data from a connected socket.
recvfrom()
Receives data from an unconnected socket.
shutdown()
Disables send or receive operations on a socket.
closesocket()
Closes a socket.
Figure 24.10 shows the operation of a connection of a client to a server. The server is defined
as the computer which waits for a connection, the client is the computer which initially
makes contact with the server.
On the server the computer initially creates a socket with the
socket()
function, and this
is bound to a name with the
bind()
function. After this, the server listens for a connection
with the
listen()
function. When the client calls the
connect()
function the server then
accepts the connection with
accept()
. After this the server and client can send and receive
data with the
send()
or
recv()
functions. When the data transfer is complete the
close-
socket()
is used to close the socket.
Server
Client
socket()
create a socket
socket()
create a socket
bind()
give socket a
name
connect()
connect to a socket
listen()
listen for
connections
accept()
accept a new
connection
send()/recv()
send/receive
data
send()/recv()
send/receive
data
closesocket()
close a socket
closesocket()
close a socket
Figure 24.10
WinSock connection
socket()
The
socket()
function creates a socket. Its syntax is