就是把socket设置成无效套接字。
if(sclient == INVALID_SOCKET) { printf("invalid socket !"); return 0; } sockaddr_in serAddr; serAddr.sin_family = AF_INET; serAddr.sin_port = htons(8888); serAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1"); if (connect(sclient, (sockaddr *)&serAddr, size...
SOCKET slisten = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(slisten == INVALID_SOCKET) { printf("socket error !"); return 0; } //绑定IP和端口 sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_port = htons(8888); sin.sin_addr.S_un.S_addr = INADDR_ANY; if(bind(slist...
=0) return 0; SOCKET sClient = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if(sClient==INVALID_SOCKET) { printf("socket error\n"); return 0; } sockaddr_in remote; remote.sin_family = AF_INET; remote.sin_port = htons(1129); remote.sin_addr.s_addr = inet_addr(...
SOCKET slisten = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); if(slisten == INVALID_SOCKET) { printf("socket error !"); return 0; } //绑定IP和端口 sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_port = htons(8888);
1:加载套接字库,创建套接字(WSAStartup()/socket()); 2:向服务器发出连接请求(connect()); 3:和服务器端进行通信(send()/recv()); 4:关闭套接字,关闭加载的套接字库(closesocket()/WSACleanup())。 函数介绍: 1.#include<sys/socket.h>
if(slisten == INVALID_SOCKET) { printf("socket error !"); return 0; } //绑定IP和端口 sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_port = htons(8888); sin.sin_addr.S_un.S_addr = INADDR_ANY; if(bind(slisten, (LPSOCKADDR)&sin, sizeof(sin)) == SOCKET_ERROR) ...
int bind(SOCKET socket, const struct sockaddr* address, socklen_t address_len); 参数说明: socket:是一个套接字描述符。 address:是一个sockaddr结构指针,该结构中包含了要结合的地址和端口号。 address_len:确定address缓冲区的长度。 返回值:
=INVALID_SOCKET)19{20printf("invalid socket !");21return0;22}2324sockaddr_in serAddr;25serAddr.sin_family =AF_INET;26serAddr.sin_port = htons(8888);27serAddr.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");28if(connect(sclient, (sockaddr *)&serAddr,sizeof(serAddr)) ==SOCKET_...
if(slisten == INVALID_SOCKET) { printf("socket error !"); return 0; } //绑定IP和端口 sockaddr_in sin; sin.sin_family = AF_INET; sin.sin_port = htons(8888); sin.sin_addr.S_un.S_addr = INADDR_ANY; if(bind(slisten, (LPSOCKADDR)&sin, sizeof(sin)) == SOCKET_ERROR) ...