Versetti Novice
Gender: Joined: Jan 05 2004 Posts: 54 Offline
|
Posted: Tue Jan 13, 2004 5:45 pm Post subject: Socket Problem |
|
|
|
|
Should this code below connect to the IRC server and go to the IRC channel #worldchat? because I tried and I don't see my program going in the channel when I'm in there I see no Dude w/e I named it entering.
Here is the code:
#include <iostream.h>
#include <winsock.h>
int main()
{
char myname[17] = " NICK Dude008\r\n";
char myuserid[38] = "USER random \"S\" \"127.0.0.1\" :random\r\n";
char mychan[18] = "JOIN #worldchat\r\n";
cout << "A tiny IRC program\n";
WSADATA WsaDat;
if (WSAStartup(MAKEWORD(1,1), &WsaDat) != 0)
{
cout << "Error: Failed to start Winsock\n";
return 0;
}
SOCKET mysocket;
mysocket = socket(AF_INET, SOCK_STREAM, 0);
SOCKADDR_IN SockAddr;
SockAddr.sin_port = htons(6667);
SockAddr.sin_family = AF_INET;
SockAddr.sin_addr.S_un.S_un_b.s_b1 = 66;
SockAddr.sin_addr.S_un.S_un_b.s_b2 = 252;
SockAddr.sin_addr.S_un.S_un_b.s_b3 = 1;
SockAddr.sin_addr.S_un.S_un_b.s_b4 = 55;
if (connect(mysocket, (SOCKADDR *)(&SockAddr), sizeof(SockAddr)) == SOCKET_ERROR)
{
cout << "Error: Socket could not connect\n";
return 0;
}
send(mysocket, myname, sizeof(myname), 0);
cout << "Sent nick\n";
Sleep(MAKEWORD(10,10));
send(mysocket, myuserid, sizeof(myuserid), 0);
cout << "Sent user id\n";
Sleep(MAKEWORD(10,10));
send(mysocket, mychan, sizeof(mychan), 0);
cout << "Joining #WorldChat\n";
Sleep(MAKEWORD(10,10));
return 0;
} |
plz help this is what I'm stuck so far o yea and also too send a chat msg in irc I just use send(mysocket, msghere,sizeof(msghere),0);
and should it send something to the chat after I connect? |
|