Server Common Model
1. Initialize the socket (for listening)
1) Initialization
SOCKET s;
s = Socket (...)
2) Binding
Bind (S, ... );
3) Monitoring
Listen (S, ... );
2. Establish a connection
1) Check the status
int ret = SELECT (...);
if (Ret > 0) {
New Connection
}
2) Establish a new connection (if a client requests a connection)
temp = accept (...); Note that you do not use the original socket at this time, but instead create a new socket (temp) to communicate with the client
3. Send and receive data
1) Detection of read-in data
int ret = SELECT (...)
if (Ret > 0) {
Have new data
}
2) Receive data
ret = recv (...);
3) Check sending data
int ret = SELECT (...);
4) Send data
ret = Send (...);
Client Common model
1. Initialization
1) Create socket
s = Socket (...)
2) Binding port
Bind (S, ...) ; The client's IP address and port do not need to be fixed and can be automatically assigned by the system. So you can bind ports and protocols without using BIND.
2. Establish a connection
Connect (...)
3. Send and receive data
With the service side
4. Close the connection
From for notes (Wiz)
Basic socket Communication Flow