Hallo,
Ik probeer een simpele socket server te schrijven met behulp van een tutorial van microsoft (http://msdn.microsoft.com/en-us/library/bb530742(VS.85).aspx). Ik gebruik Borland Builder 5.5.
Dit is de code:
Dit is de output van bcc32 (de compiler):
Als ik vervolgens de code aanpas, dus afwijk van de tutorial van microsoft, krijg ik met de volgende code:
De volgende output:
Heb ik zo de eerste 7 errors goed opgelost? En hoe los ik de laatste 3 op?
Bij voorbaat dank,
Wessel.
Ik probeer een simpele socket server te schrijven met behulp van een tutorial van microsoft (http://msdn.microsoft.com/en-us/library/bb530742(VS.85).aspx). Ik gebruik Borland Builder 5.5.
Dit is de code:
Code:
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#define DEFAULT_PORT "27015"
int main()
{
WSADATA wsaData;
int iResult;
struct addrinfo *result = NULL, *ptr = NULL, hints;
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE;
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0)
{
printf("WSAStartup failed: %d\n", iResult);
return 1;
}
return 0;
}
Dit is de output van bcc32 (de compiler):
Code:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
test.cpp:
Error E2450 test.cpp 11: Undefined structure 'addrinfo' in function main()
Error E2449 test.cpp 11: Size of 'hints' is unknown or zero in function main()
Error E2450 test.cpp 11: Undefined structure 'addrinfo' in function main()
Error E2450 test.cpp 13: Undefined structure 'addrinfo' in function main()
Error E2109 test.cpp 13: Not an allowed type in function main()
Error E2315 test.cpp 14: 'ai_family' is not a member of 'addrinfo', because the type is not yet defined in function main()
Error E2315 test.cpp 15: 'ai_socktype' is not a member of 'addrinfo', because the type is not yet defined in function main()
Error E2315 test.cpp 16: 'ai_protocol' is not a member of 'addrinfo', because the type is not yet defined in function main()
Error E2315 test.cpp 17: 'ai_flags' is not a member of 'addrinfo', because the type is not yet defined in function main()
Error E2451 test.cpp 17: Undefined symbol 'AI_PASSIVE' in function main()
Warning W8004 test.cpp 28: 'ptr' is assigned a value that is never used in function main()
Warning W8004 test.cpp 28: 'result' is assigned a value that is never used in function main()
*** 10 errors in Compile ***
Als ik vervolgens de code aanpas, dus afwijk van de tutorial van microsoft, krijg ik met de volgende code:
Code:
#include <winsock2.h>
#include <ws2tcpip.h>
#include <stdio.h>
#define DEFAULT_PORT "27015"
#define struct addrinfo *result = NULL, *ptr = NULL, hints;
int main()
{
WSADATA wsaData;
int iResult;
ZeroMemory(&hints, sizeof(hints));
hints.ai_family = AF_INET;
hints.ai_socktype = SOCK_STREAM;
hints.ai_protocol = IPPROTO_TCP;
hints.ai_flags = AI_PASSIVE;
iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
if (iResult != 0)
{
printf("WSAStartup failed: %d\n", iResult);
return 1;
}
return 0;
}
De volgende output:
Code:
Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland
test.cpp:
Error E2451 test.cpp 13: Undefined symbol 'hints' in function main()
Error E2109 test.cpp 13: Not an allowed type in function main()
Error E2451 test.cpp 17: Undefined symbol 'AI_PASSIVE' in function main()
*** 3 errors in Compile ***
Heb ik zo de eerste 7 errors goed opgelost? En hoe los ik de laatste 3 op?
Bij voorbaat dank,
Wessel.