sockets - VC++ Winsock2 Error 10049. Trying to build IRC bot -


I am trying to shut down my IRC boat from Python to C ++ and I have some issues with Winsock2 I'm going I am new to Socket in C / C ++ and most of this code was mixed with various tutorials. I'm getting 10049 error and am damn any help would be greatly appreciated!

port_ is set to 6667 and host_ is "irc.rizon.net"

  WSADATA wsaData; Int starter = WSAStartup (MacWorld (2,2), and Wisadata); If (starter! = 0) {std :: cout & lt; & Lt; "Error:" & lt; & Lt; WSAGetLastError () & lt; & Lt; "Happened!" & Lt; & Lt; Std :: endl; WSACleanup (); Return 1; } Std :: cout & lt; & Lt; "WSAS startup successful!" & Lt; & Lt; Std :: endl; Socketfd_ = Socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); If (socketfd_ == INVALID_SOCKET) {std :: cout & lt; & Lt; "Error:" & lt; & Lt; WSAGetLastError () & lt; & Lt; "Happened!" & Lt; & Lt; Std :: endl; WSACleanup (); Return 1; } Std :: cout & lt; & Lt; "Socket Creation Success!" & Lt; & Lt; Std :: endl; Socreadth_inense; Anews.sin_port = htons (port_); Anews.sin_addr.s_addr = inet_addr (host_.c_str ()); Anews.sin_family = AF_INET; If (connect (socketfd _, (Socadar *) and grain, anews) == SOCKET_ERROR) {std :: cout & lt; & Lt; "Error:" & lt; & Lt; WSAGetLastError () & lt; & Lt; "Happened!" & Lt; & Lt; Std :: endl; WSACleanup (); Return 1; } Std :: cout & lt; & Lt; "Socket is successfully linked!" & Lt; & Lt; Std :: endl; Return 0;    

inet_addr () takes a dotted IP address "Xxxx" You are giving it host name.

You can use gethostbyname () :

  hostent * host; Four * IP; ... // Get local host information host = gethostbyname (host_.c_str ()); Ip = inet_ntoa (* (struct in_addr *) * host-> h_addr_list); Socreadth_inense; Anews.sin_port = htons (port_); Anews.sin_addr.s_addr = inet_addr (IP); Anews.sin_family = AF_INET; ...   

Or use an easy route getaddrinfo ():

  struct addrinfo * ai; If (getaddrinfo (host_.c_str (), "6667", tap, & amp; AI) = 0) 1 return; Socketfd_ = Socket (AI-> ai_family, SOCK_STREAM, 0); If (socketfd_ == INVALID_SOCKET) {freeandrino (AI); Return 1} if (connect (socketfd_, ai-> ai_addr, (int) ai-> ai_addrlen) == SOCKET_ERROR) {port (socketfd_); Freeaddrinfo (AI); Return 1; } ...    

Comments

Popular posts from this blog

mysql - BLOB/TEXT column 'value' used in key specification without a key length -

c# - Using Vici cool Storage with monodroid -

python - referencing a variable in another function? -