-
September 17th, 2009, 09:25 AM
#1
Connecting to AIM TOC
Code:
char * AIMIP = "64.12.203.86";
//toc.oscar.aol.com
//"205.188.213.226";
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? =(
-
September 17th, 2009, 11:30 AM
#2
Re: Connecting to AIM TOC
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."
(from http://msdn.microsoft.com/en-us/libr...8VS.85%29.aspx)
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.
-
September 17th, 2009, 11:42 AM
#3
Re: Connecting to AIM TOC
Hmmm. I can connect just fine. It appears to be an HTTP server. a HEAD request give:
Code:
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>
-
September 17th, 2009, 11:59 AM
#4
Re: Connecting to AIM TOC
But... HTTP is on top of INET STREAM.... :-/ So how would that make sence?
U use port 5190?
-
September 17th, 2009, 04:30 PM
#5
Re: Connecting to AIM TOC
Originally Posted by AgentSmithers
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?
-
September 17th, 2009, 08:00 PM
#6
Re: Connecting to AIM TOC
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
-
September 18th, 2009, 08:10 AM
#7
Re: Connecting to AIM TOC
No, there's not nearly enough there to compile.
-
September 18th, 2009, 09:31 AM
#8
Re: Connecting to AIM TOC
Here's a complete working example:
Code:
#include <windows.h>
#include <winsock.h>
#pragma comment(lib, "Ws2_32.lib")
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
int sock,len;
unsigned long in_addr;
struct sockaddr_in client;
char c,buf[50];
WSADATA wsa;
if(WSAStartup(0x0101,&wsa)){
fprintf(stderr,"Unable to start winsock (%d)\n",WSAGetLastError());
return EXIT_FAILURE;
}
memset(&client,0,sizeof(client));
client.sin_family=AF_INET;
in_addr=inet_addr("64.12.203.86");
if(in_addr!=INADDR_NONE){
memcpy(&client.sin_addr,&in_addr,sizeof(in_addr));
}else{
fprintf(stderr,"Unable to parse address (%d)\n",WSAGetLastError());
return EXIT_FAILURE;
}
client.sin_port=htons(5190);
sock=(int)socket(AF_INET,SOCK_STREAM,0);
if(sock==SOCKET_ERROR){
fprintf(stderr,"Unable to create socket (%d)\n",WSAGetLastError());
return EXIT_FAILURE;
}
if(connect(sock,(struct sockaddr *)&client,sizeof(client))==SOCKET_ERROR){
closesocket(sock);
fprintf(stderr,"Unable to connect (%d)\n",WSAGetLastError());
return EXIT_FAILURE;
}
sprintf(buf,"HEAD / HTTP/1.0\r\n\r\n");
len=strlen(buf);
if(send(sock,buf,len,0)!=len){
closesocket(sock);
fprintf(stderr,"send() failed (%d)\n",WSAGetLastError());
return EXIT_FAILURE;
}
while(recv(sock,&c,1,0)){
printf("%c",c);
}
closesocket(sock);
WSACleanup();
return EXIT_SUCCESS;
}
Output:
Code:
HTTP/1.1 501 Not Implemented
Date: Fri
Server: TOC/1.0
Connection: close
Content-type: text/html
<HTML><HEAD><TITLE>501 Not Implemented</TITLE></HEAD><BODY><H1>This Feature is n
ot implemented</H1></BODY></HTML>
-
September 19th, 2009, 11:40 PM
#9
Re: Connecting to AIM TOC
Main.AimSocketInfo.sin_family = AF_INET; //Assine IPv4 To Socket's Was the issue I never had that in my code... Weird?
Im very supprised that
((AimSocket.sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == SOCKET_ERROR)
dosent take care of that.
-
September 20th, 2009, 12:18 AM
#10
Re: Connecting to AIM TOC
-
September 20th, 2009, 02:02 AM
#11
Re: Connecting to AIM TOC
No a peice of code was missing my, My post above.
-
September 20th, 2009, 10:58 AM
#12
Re: Connecting to AIM TOC
Unless you have some weird configuration, AF_INET should be the same as PF_INET
-
September 20th, 2009, 11:13 AM
#13
Re: Connecting to AIM TOC
-
September 20th, 2009, 11:57 AM
#14
Re: Connecting to AIM TOC
So how is it possible that changing that fixed your problem?
-
September 20th, 2009, 12:20 PM
#15
Re: Connecting to AIM TOC
Code:
Main.AimSocketInfo.sin_family = AF_INET;
The Code above is required with the code below to work
Code:
((AimSocket.sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) == SOCKET_ERROR)
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|