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

The short answer is yes.

The longer answer is, not without difficulty. Sure you may be able to connect, but is the protocol published, or is it proprietary to Yahoo?

If there's a library, you should invest some time in trying to get it to work. It will save you a lot of grief in the long run.

Perhaps post a simple program using the library, and the error message(s) you get.

ummm.....the libyahoo2 protocol...I really dont know too much about it.

Actually, I am learning Winsock and since I have been wanting to make an Instant messenger I started with a yahoo. I understand it will be difficult, and i suppose I will create a separate project to try again on the libyahoo2 library, but I want to continue trying to make winsock work.

At the moment, the following code doesnt connect. As programmed, it displays

error: unable to connect.

I figured it out...it should have been :

YaSocket = socket(AF_INET,SOCK_STREAM, IPPROTO_TCP);
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.