-
Winsock
Hmm... I was using Winsock in a console (following a random tutorial I found on the internet) and so far I wanted to see if I got any errors. So I wrote all the code (that I have read):
Code:
#include <iostream>
#include <windows.h>
int main( void )
{
WSADATA wsaDat;
if( WSAStartup( ( 1, 1 ), &wsaDat ) != 0 )
{
std::cout << "WSA initialization failed!";
}
SOCKET socket;
socket = ( AF_INET, SOCK_STREAM, 0 );
if( socket == INVALID_SOCKET )
{
std::cout << "Failed to create socket!";
}
SOCKADDR_IN sockAddr;
sockAddr.sin_port = 50;
sockAddr.sin_family = AF_INET;
sockAddr.sin_addr.S_un.S_un_b.s_b1 = 127;
sockAddr.sin_addr.S_un.S_un_b.s_b2 = 0;
sockAddr.sin_addr.S_un.S_un_b.s_b3 = 0;
sockAddr.sin_addr.S_un.S_un_b.s_b4 = 1;
if( bind( socket, ( SOCKADDR* )( &sockAddr ), sizeof( sockAddr ) ) == SOCKET_ERROR )
{
std::cout << "Failed to bind!";
}
std::cin.get();
return 0;
}
I linked libwsock.a and ended with a single error:
[Build Error] ["Internet.exe"] Error 1
I haven't found anything to cause that error yet. See signature for compiler etc.
- SirCrono6
P.S. Ah! Haven't seen C++ code in so long! :D
-
It has nothing to do with C++, it is all about your knowledge of networking.
For instance, where is your include file for winsock?
Something like this is expected:
Code:
#include <WINSOCK2.h>
This is for the new version of winsock.
Also this:
Code:
if( WSAStartup( ( 1, 1 ), &wsaDat ) != 0 )
You are missing something in here, such as the MAKEWORD macro, aka
Code:
if( WSAStartup( MAKEWORD( 1, 1 ), &wsaDat ) != 0 )
And are you linking with the correct library?
Plus this does belong in the Networking Forum.
Anywho, hope this helps.
edit: Just bothered to read your sig, you have the newest version of winsock. You should use it.