irc via socket
-
using a socket I'm connecting to an irc server, when i do i get: NOTICE AUTH :*** Processing connection to efnet.demon.co.uk NOTICE AUTH :*** Looking up your hostname... NOTICE AUTH :*** Checking Ident NOTICE AUTH :*** Found your hostname NOTICE AUTH :*** Got Ident response this is all i get no welcome message, no matter what i send through this socket i don't get any response. then after a while i get: ERROR :Closing Link: 127.0.0.1 (Connection timed out) thanks
-
using a socket I'm connecting to an irc server, when i do i get: NOTICE AUTH :*** Processing connection to efnet.demon.co.uk NOTICE AUTH :*** Looking up your hostname... NOTICE AUTH :*** Checking Ident NOTICE AUTH :*** Found your hostname NOTICE AUTH :*** Got Ident response this is all i get no welcome message, no matter what i send through this socket i don't get any response. then after a while i get: ERROR :Closing Link: 127.0.0.1 (Connection timed out) thanks
What do you mean, you "get" that from the server? How are you receiving that text? Are you sending the appropriate messages to connect to the server, as per the IRC protocol? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
What do you mean, you "get" that from the server? How are you receiving that text? Are you sending the appropriate messages to connect to the server, as per the IRC protocol? Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
What do you mean, you "get" that from the server? How are you receiving that text? yes that is what i get from the server when i connect, via recv (s, buffer,bufferSize, 0); Are you sending the appropriate messages to connect to the server, as per the IRC protocol? not sure, according to this all you have to do is send commands like NICK name etc, once you are connected, but it doesn't seem to be working. http://www.irchelp.org/irchelp/rfc/rfc.html
-
What do you mean, you "get" that from the server? How are you receiving that text? yes that is what i get from the server when i connect, via recv (s, buffer,bufferSize, 0); Are you sending the appropriate messages to connect to the server, as per the IRC protocol? not sure, according to this all you have to do is send commands like NICK name etc, once you are connected, but it doesn't seem to be working. http://www.irchelp.org/irchelp/rfc/rfc.html
It's impossible to say without seeing any code, but things to look at are: 1) Parsing messages from the server - the protocol doesn't include message length parameters so it's up to you to recv() all bytes whenever there's an FD_READ event and parse the bytes into messages. Remember, on one recv(), you may only get a partial message. You have to deal with that. 2) Make sure you're forming your client-to-server messages correctly. ASCII only - no Unicode. Use proper whitespace. Check for server replies. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
It's impossible to say without seeing any code, but things to look at are: 1) Parsing messages from the server - the protocol doesn't include message length parameters so it's up to you to recv() all bytes whenever there's an FD_READ event and parse the bytes into messages. Remember, on one recv(), you may only get a partial message. You have to deal with that. 2) Make sure you're forming your client-to-server messages correctly. ASCII only - no Unicode. Use proper whitespace. Check for server replies. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
connect function experimenting with:
int Client::Connect(HWND hwnd) { // Initialize Winsock version 2.2 char message[200]; cUser user; // struct user sprintf(user.nick,"myNic"); sprintf(user.ident,"IDspoonMan"); sprintf(user.email,"vertexar@yahoo.com"); sprintf(message,"USER %s %s: %s %s \n\r", user.nick , user.email , user.ident , user.ident ); Port = 6667; WSAStartup(MAKEWORD(1,1), &wsaData); LPHOSTENT hostEntry; //store information about the server hostEntry = gethostbyname("efnet.demon.co.uk"); if(!hostEntry) { ::MessageBox(NULL,"Failed gethostbyname()","Error",0); //WSACleanup(); } // Create a new socket to make a client connection. s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); ServerAddr.sin_family = AF_INET; ServerAddr.sin_port = htons(Port); //ServerAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); ServerAddr.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list); // Mark our socket non-blocking, and ask for asynch notifications. if (WSAAsyncSelect(s, hwnd, customClientMessage,FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE) == SOCKET_ERROR) { ::MessageBox(NULL,"TSWCCould not set to non-blocking! ", "ERROR..", MB_OK); //REPORT_PROBLEM(WSAGetLastErrorMessage("WSAAsyncSelect failed.")); return false; } int CON_ERROR = connect(s, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr)); //send(s, message, strlen(message), 0); //sprintf(message,"NICK %s\n\r", user.nick); //send(s, message, strlen(message), 0); Sleep(10); send(s,"NICK mynic \n\r",15,0); send(s,"USER mynic 0 * myname \n\r",27,0); int errorCode = WSAGetLastError(); if(!CON_ERROR) return true; return false; }
using telnet i tried this and it works: o efnet.demon.co.uk 6667 NICK mynic USER mynic 0 * myname i dont see why is not working when i send it through my socket. -
connect function experimenting with:
int Client::Connect(HWND hwnd) { // Initialize Winsock version 2.2 char message[200]; cUser user; // struct user sprintf(user.nick,"myNic"); sprintf(user.ident,"IDspoonMan"); sprintf(user.email,"vertexar@yahoo.com"); sprintf(message,"USER %s %s: %s %s \n\r", user.nick , user.email , user.ident , user.ident ); Port = 6667; WSAStartup(MAKEWORD(1,1), &wsaData); LPHOSTENT hostEntry; //store information about the server hostEntry = gethostbyname("efnet.demon.co.uk"); if(!hostEntry) { ::MessageBox(NULL,"Failed gethostbyname()","Error",0); //WSACleanup(); } // Create a new socket to make a client connection. s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); ServerAddr.sin_family = AF_INET; ServerAddr.sin_port = htons(Port); //ServerAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); ServerAddr.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list); // Mark our socket non-blocking, and ask for asynch notifications. if (WSAAsyncSelect(s, hwnd, customClientMessage,FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE) == SOCKET_ERROR) { ::MessageBox(NULL,"TSWCCould not set to non-blocking! ", "ERROR..", MB_OK); //REPORT_PROBLEM(WSAGetLastErrorMessage("WSAAsyncSelect failed.")); return false; } int CON_ERROR = connect(s, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr)); //send(s, message, strlen(message), 0); //sprintf(message,"NICK %s\n\r", user.nick); //send(s, message, strlen(message), 0); Sleep(10); send(s,"NICK mynic \n\r",15,0); send(s,"USER mynic 0 * myname \n\r",27,0); int errorCode = WSAGetLastError(); if(!CON_ERROR) return true; return false; }
using telnet i tried this and it works: o efnet.demon.co.uk 6667 NICK mynic USER mynic 0 * myname i dont see why is not working when i send it through my socket.You're not using asynchronous sockets correctly. You should be checking if connect() is successful. If it's not, you need to check the error code - if it's WSAEWOULDBLOCK, then you need to wait until the socket is connected before writing data to it. You'll know this when you get the FD_CONNECT notification, at which time you need to check for errors again, to make sure the connection succeeded. THEN you can write data to the socket. "Sleep(10)" is really bad design. It could take hundreds or thousands of milliseconds to connect. Maybe you'll get lucky and connect() will succeed instantly (unlikely when connecting to a WAN address) - you don't check for that though. Mark
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
connect function experimenting with:
int Client::Connect(HWND hwnd) { // Initialize Winsock version 2.2 char message[200]; cUser user; // struct user sprintf(user.nick,"myNic"); sprintf(user.ident,"IDspoonMan"); sprintf(user.email,"vertexar@yahoo.com"); sprintf(message,"USER %s %s: %s %s \n\r", user.nick , user.email , user.ident , user.ident ); Port = 6667; WSAStartup(MAKEWORD(1,1), &wsaData); LPHOSTENT hostEntry; //store information about the server hostEntry = gethostbyname("efnet.demon.co.uk"); if(!hostEntry) { ::MessageBox(NULL,"Failed gethostbyname()","Error",0); //WSACleanup(); } // Create a new socket to make a client connection. s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); ServerAddr.sin_family = AF_INET; ServerAddr.sin_port = htons(Port); //ServerAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); ServerAddr.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list); // Mark our socket non-blocking, and ask for asynch notifications. if (WSAAsyncSelect(s, hwnd, customClientMessage,FD_READ | FD_WRITE | FD_CONNECT | FD_CLOSE) == SOCKET_ERROR) { ::MessageBox(NULL,"TSWCCould not set to non-blocking! ", "ERROR..", MB_OK); //REPORT_PROBLEM(WSAGetLastErrorMessage("WSAAsyncSelect failed.")); return false; } int CON_ERROR = connect(s, (SOCKADDR *) &ServerAddr, sizeof(ServerAddr)); //send(s, message, strlen(message), 0); //sprintf(message,"NICK %s\n\r", user.nick); //send(s, message, strlen(message), 0); Sleep(10); send(s,"NICK mynic \n\r",15,0); send(s,"USER mynic 0 * myname \n\r",27,0); int errorCode = WSAGetLastError(); if(!CON_ERROR) return true; return false; }
using telnet i tried this and it works: o efnet.demon.co.uk 6667 NICK mynic USER mynic 0 * myname i dont see why is not working when i send it through my socket.Lamefif wrote:
using telnet i tried this and it works: o efnet.demon.co.uk 6667 NICK mynic USER mynic 0 * myname i dont see why is not working when i send it through my socket.
My suggestion, either stick with a blocking socket so you can connect+send+evaluate... or use an non-blocking socket (something like CAsyncSocket). In the later case you would register an event handler for OnConnect(): socket got connected and you can send login information, plus an event handler for OnReceive(): more data has been received. It probably helps to have a look at example code. /M