Connecting to AIM TOC
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15

Thread: Connecting to AIM TOC

  1. #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? =(

  2. #2
    Join Date
    Feb 2005
    Posts
    2,160

    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.

  3. #3
    Join Date
    Feb 2005
    Posts
    2,160

    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>

  4. #4

    Re: Connecting to AIM TOC

    But... HTTP is on top of INET STREAM.... :-/ So how would that make sence?

    U use port 5190?

  5. #5
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Connecting to AIM TOC

    Quote Originally Posted by AgentSmithers View Post
    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?

  6. #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

  7. #7
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Connecting to AIM TOC

    No, there's not nearly enough there to compile.

  8. #8
    Join Date
    Feb 2005
    Posts
    2,160

    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>

  9. #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.

  10. #10
    Join Date
    Jan 2006
    Location
    Chicago, IL
    Posts
    14,982

    Re: Connecting to AIM TOC

    Router blocking it?
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  11. #11

    Re: Connecting to AIM TOC

    No a peice of code was missing my, My post above.

  12. #12
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Connecting to AIM TOC

    Unless you have some weird configuration, AF_INET should be the same as PF_INET

  13. #13

    Re: Connecting to AIM TOC

    It is....

  14. #14
    Join Date
    Feb 2005
    Posts
    2,160

    Re: Connecting to AIM TOC

    So how is it possible that changing that fixed your problem?

  15. #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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center