在winsock中,應用程序通過Sockaddr_in 結構來指定IP地址和服務端口信息:
sockaddr_in internetAddr;
int nPortID = 5320;
internetAddr.sin_family = AF_INET;
internetAddr.sin_addr.s_addr = inet_addr(“202.202.42.88”);
internetAddr.sin_port = htons(nPortID);
ip地址不容易記憶,還提供了許多地址和名稱解析函數如gethostbyname,gethostbyaddr等
=======服務器=======
#include <stdio.h><winsock2.h> comment (lib,"WS2_32") main( argc, * servport = buff[ (WSAStartup(,&ws) != - printf(= socket(AF_INET,SOCK_STREAM, memset(&sa,,=== inet_addr( printf(= bind(servsock,( sockaddr*)&sa,(err != - printf(= listen(servsock,(err != - printf(= =accept(servsock,( sockaddr*)&cliaddr,&