理解TCP/UDP

1:  IP层是面向消息的,不可靠的协议。是解决数据传输中的路径选择问题

2:TCP/UDP 决定了主机之间的数据传输方式。

3: server and  Client

Server

  1. Initialize Winsock   2。  Create a socket Bind the socket.         3     Listen on the socket for a client. 4   Accept a connection from a client.  5 Receive and send data   6 Disconnect.

Client

1.Initialize Winsock  2.Create a socket   3.Connect to the server  4.Send and receive data     5.Disconnect

 

4.WSDA结构体

typedef struct WSAData {
  WORD           wVersion;
  WORD           wHighVersion;
  unsigned short iMaxSockets;
  unsigned short iMaxUdpDg;
  char           *lpVendorInfo;
  char           szDescription[WSADESCRIPTION_LEN + 1];
  char           szSystemStatus[WSASYS_STATUS_LEN + 1];
  char           szDescription[WSADESCRIPTION_LEN + 1];
  unsigned short iMaxSockets;
  unsigned short iMaxUdpDg;
  char           *lpVendorInfo;
} WSADATA;

  5.WSAStartup 结构体

int WSAStartup(
  WORD      wVersionRequired,
  LPWSADATA lpWSAData
);

wVersionRequired

TBD

lpWSAData

A pointer to the WSADATA data structure that is to receive details of the Windows Sockets implementation.

If successful, the WSAStartup function returns zero. Otherwise, it returns one of the error codes listed below.

各种常见错误:

理解TCP/UDP_第1张图片

6.结构体:addinfo

typedef struct addrinfo {
  int             ai_flags;
  int             ai_family;
  int             ai_socktype;
  int             ai_protocol;
  size_t          ai_addrlen;
  char            *ai_canonname;
  struct sockaddr *ai_addr;
  struct addrinfo *ai_next;
} ADDRINFOA, *PADDRINFOA;

7.结构体:sockaddr

struct sockaddr {
        ushort  sa_family;
        char    sa_data[14];
};

struct sockaddr_in {
        short   sin_family;
        u_short sin_port;
        struct  in_addr sin_addr;
        char    sin_zero[8];
};

 

 

你可能感兴趣的:(TCP/IP)