Click to See Complete Forum and Search --> : Winsock yahoo: scs.msg.yahoo.com server


zaryk
October 26th, 2008, 09:35 PM
Is it possible to connect to yahoo server using Winsock or do I have to use a library like libyahoo2. I know that it will much harder to do it with Winsock, but then again I have already looked at libyahoo2 and couldn't get anything to work.



#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();
}

zaryk
October 27th, 2008, 02:08 PM
I guess I should post this in network programming......though it is included in c++ winapi program.