您的位置:

c语言socketerror,c语言socket编程

本文目录一览:

C语言,socket为什么运行不了,我这个是关于udp通信的接收方代码

s = socket(AF_INET, SOCK_DGRAM, 0); // 1

if (WSAStartup(MAKEWORD(2,2), wsd) != 0) // 2

{

printf("Failed to load Winsock!\n");

return 1;

}

1、2反了,要先初始化才能socket。既然你用vs,推荐你看一下《Windows网络编程技术》和配套代码,可以省去很多麻烦。

C语言编写SOCKET基本套接字的使用,出错了```高手指点下```

除了包含头文件还要加入socket库。

加上这一句就行了!

#pragma comment(lib,"WS2_32.lib");

C语言socket连接问题!

#include windows.h #include stdio.h #include winsock.h #pragma comment(lib,"ws2_32") #define PORT 1129 #define ADDRESS "127.0.0.1/socket.asp" int main() { WSADATA wsaData; WORD sockVersion = MAKEWORD(2,2); if(WSAStartup(sockVersion,wsaData)!=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(ADDRESS); if(connect(sClient,(SOCKADDR *)remote,sizeof(SOCKADDR))==SOCKET_ERROR) { printf("connect error\n"); closesocket(sClient); return 0; } while(true) { char SendData[255]; int i,ch; for( i = 0; (i 254) ((ch = getchar()) != EOF) (ch!='\n'); i++) SendData[i] = (char)ch; SendData[i] = '\n'; SendData[i+1] = '\0'; send(sClient,SendData,i+2,0); } closesocket(sClient); WSACleanup(); return 0; } //帮你修改了下...可编译过...VC6.0

C语言SOCKET问题

exit(0);是对的。

在void main() 上新加一行

#pragma comment(lib, "ws2_32.lib")

应该就可以了