您好,我是初学者 socket/c 程序员,从本教程中我有连接函数返回 10038 错误。请帮忙。我究竟做错了什么?
还有winsock和winsock2有什么区别?在 connect() 函数定义中还有 int PASCAL 什么是 pascal ?
#include <iostream>
#include <winsock.h>
using namespace std;
int main(){
WSADATA wsa;
cout<< "Iinitializing winsock....";
SOCKET sa;
struct sockaddr_in server;
if (WSAStartup(MAKEWORD(2,2), &wsa)!=0)
cout << "Failed";
cout << "initialized";
if ((sa = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP) == INVALID_SOCKET))
cout << "Could not create socket " << WSAGetLastError();
cout << "Socket created";
server.sin_addr.s_addr = inet_addr ("213.165.64.44");
server.sin_family = AF_INET;
server.sin_port = htons(7);
//connect
if (connect(sa, (struct sockaddr *)&server, sizeof(server)) < 0){
cerr << "connect error" << WSAGetLastError();
return 1;
}
cout << "connected";
return 0;
}