Socket通信基本流程

转自 : http://blog.csdn.net/lyd_253261362/article/details/4394370



Tcp通信基本流程:

服务器端                                                                       客户端

1.创建socket                                                                1.创建socket

2.bind()                                                                         

3.listen()

4.accecp()

----等待客户端连接----                                                    2.connect()

5.读数据(recv)                                                          3.写数据(send)

6.写数据(send)                                                         4.读数据(recv)

7.关闭socket(closesocket())                                 5.关闭socket(closesocket())

 

 

Udp通信基本流程:

服务器端:                                                                    客户端

1.创建socket                                                                1.创建socket

2.bind()                                                                    2.bind()

3.recvfrom                         

----等待连接----                                                              3.sendto()

4.sendto()                                                                4.recvfrom()

5.关闭socket(closesocket())                                   5.关闭socket(closesocket())


你可能感兴趣的:(tcp,socket,服务器)