zaryk 23 Newbie Poster

Is it possible to connect to yahoo server using winsock. I know I could use libyahoo2 but I have already tried libyahoo2 but didnt get any where. If not possible with winsock, I can try libyahoo2 again.

#include <windows.h>

#define YaMainServer                    "scs.msg.yahoo.com"
#define YaMainServerPort              5050

void YahooSock(HWND hwnd){
     
     int YaConnect;
     int error;
     WORD SockVer = MAKEWORD(2, 2);
     WSADATA YaData;

    error = WSAStartup(MAKEWORD(2, 2), &YaData);

    if (error == SOCKET_ERROR)
    {
        MessageBox(hwnd, "Unable to Initialize Windows Socket environment", "Error", MB_OK);
        return;
    } 
          
     LPHOSTENT YaHostServer;

	YaHostServer = gethostbyname(YaMainServer);

	if (!YaHostServer)
	{
       MessageBox(hwnd, "Specifying the server by its name", "Error", MB_OK);
		WSACleanup();
		return;
	}

     SOCKET YaSocket;
     
     YaSocket = (AF_INET,SOCK_STREAM, IPPROTO_TCP);
     
     if ( YaSocket == INVALID_SOCKET )
    {
        MessageBox(hwnd, "Unable to create Server socket", "Error", MB_OK);
        
        WSACleanup( ) ;
        return;
    }
    
    SOCKADDR_IN YaSockIn;
    
    YaSockIn.sin_family = AF_INET;
   YaSockIn.sin_addr = *((IN_ADDR *)YaHostServer->h_addr);
   YaSockIn.sin_port = htons(YaMainServerPort); 
   memset(&(YaSockIn.sin_zero), 0, 8); 
   
	
   YaConnect = connect(YaSocket,
		       (LPSOCKADDR)&YaSockIn,
		       sizeof(struct sockaddr));

  
	if (YaConnect == SOCKET_ERROR)
	{
       MessageBox(hwnd, "Unable to Connect", "Error", MB_OK);
		WSACleanup();
		return;
	}
    
    MessageBox(hwnd, "Connected", "YAY!", MB_OK);
    closesocket(YaSocket);
	WSACleanup();
     }
Salem commented: Congrats on using code tags on the first attempt - better than 99% of 1-posters on this forum +23