q980764821 2015年09月07日
socket客户端里connect内存冲突
//****************************客户端***********************************

#pragma warning(disable: 4996)
#include<stdio.h>
#include<stdlib.h>
#include<WinSock2.h>
#pragma comment(lib,"ws2_32.lib")
void main()
{
WSADATA wsadata;
int iResult = WSAStartup(MAKEWORD(2, 2), &wsadata);
if (iResult != NO_ERROR)
printf("Error at WSAStartup()\n");


SOCKET server;
server = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (server == INVALID_SOCKET){
printf("Error at socket():%1d");
WSACleanup();
return;
}

SOCKADDR_IN clientService;
clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr("192.168.1.1");
clientService.sin_port = htons(8080);

if (connect(server, (SOCKADDR*)&clientService, sizeof(SOCKADDR)) ==SOCKET_ERROR){
printf("Failed to connect: %s\n",GetLastError());

WSACleanup();
closesocket(server);

return;
}
/* 不知道是什么原因 */
...全文
93 点赞 收藏 12
写回复
12 条回复

还没有回复,快来抢沙发~

发动态
发帖子
C语言
创建于2007-09-28

3.2w+

社区成员

24.0w+

社区内容

C语言相关问题讨论
社区公告
暂无公告