struct TCP
{
SOCKET sock;
int TotalBytesRecv; //Total Number Of Bytes Recved
long PacketLength; //Total Number Of Bytes Expected to complete packet
char HeapBuffer[SizeOfBuffer];
} AimSocket;
if (AimSocket.sock != NULL) if (closesocket(AimSocket.sock) == SOCKET_ERROR && WSAGetLastError() != WSAENOTSOCK) return false; //WSAENOTSOCK For socket if already Closed...
if ((AimSocket.sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == SOCKET_ERROR) return false; // Error creating socket
//if (WSAAsyncSelect(AimSocket.sock , Main.hWnd, (WM_USER + 2), FD_READ | FD_CLOSE | FD_CONNECT) != 0) return false; //This makes sockets NON-Blocking and Will Report issues such as Failed Connections with in this case Windows Messages
Main.AimSocketInfo.sin_port = htons(5190); //atoi(pch + 5) Gets Port Number and Cast To Int
if ((Main.AimSocketInfo.sin_addr.S_un.S_addr = inet_addr(AIMIP)) == INADDR_NONE) return false;
if (connect(AimSocket.sock, (sockaddr *)&Main.AimSocketInfo, sizeof(sockaddr_in)) == SOCKET_ERROR)
{
int WSAError = WSAGetLastError();
OutputDebugString("Failed To Connect To AIM");
return false;
}
I get WSAEAFNOSUUPORT (10047) when trying to connect to TOC, Anyone know why? =(
hoxsiew
September 17th, 2009, 12:30 PM
Well, the obvious answer:
"Address family not supported by protocol family.
An address incompatible with the requested protocol was used. All sockets are created with an associated address family (that is, AF_INET for Internet Protocols) and a generic protocol type (that is, SOCK_STREAM). This error is returned if an incorrect protocol is explicitly requested in the socket call, or if an address of the wrong family is used for a socket, for example, in sendto."
If your code is correct (looks OK at first glance; but you don't show us Main.AimSocketInfo), then whatever is listening on port 5190 at 64.12.203.86 is not AF_INET/TCP.
hoxsiew
September 17th, 2009, 12:42 PM
Hmmm. I can connect just fine. It appears to be an HTTP server. a HEAD request give:
HTTP/1.1 501 Not Implemented
Date: Thu
Server: TOC/1.0
Connection: close
Content-type: text/html
<HTML><HEAD><TITLE>501 Not Implemented</TITLE></HEAD><BODY><H1>This Feature is not implemented</H1></BODY></HTML>
AgentSmithers
September 17th, 2009, 12:59 PM
But... HTTP is on top of INET STREAM.... :-/ So how would that make sence?
U use port 5190?
hoxsiew
September 17th, 2009, 05:30 PM
But... HTTP is on top of INET STREAM.... :-/ So how would that make sence?
U use port 5190?
I did. It must be something else. Can you show your complete code?
AgentSmithers
September 17th, 2009, 09:00 PM
From what im aware of that is everything. Just place that code into a Int Main(void) and run it, Should work just fine... as long as you of course Link and Include Winsock
The Code on bottom alone is not enough to have the socket work with IPV4, Which is odd, you think if you were to create a Socket with PF_INET/AF_INET the connect would be able to establish a connection just fine, Ignore the PF/AF its the same thing. I was just missing the line above, After that everything was peachy.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.