Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. irc via socket

irc via socket

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminhelp
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Adno
    wrote on last edited by
    #1

    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

    M 1 Reply Last reply
    0
    • A Adno

      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

      M Offline
      M Offline
      Mark Salsbery
      wrote on last edited by
      #2

      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:

      A 1 Reply Last reply
      0
      • M Mark Salsbery

        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:

        A Offline
        A Offline
        Adno
        wrote on last edited by
        #3

        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

        M 1 Reply Last reply
        0
        • A Adno

          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

          M Offline
          M Offline
          Mark Salsbery
          wrote on last edited by
          #4

          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:

          A 1 Reply Last reply
          0
          • M Mark Salsbery

            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:

            A Offline
            A Offline
            Adno
            wrote on last edited by
            #5

            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.

            M M 2 Replies Last reply
            0
            • A Adno

              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.

              M Offline
              M Offline
              Mark Salsbery
              wrote on last edited by
              #6

              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:

              1 Reply Last reply
              0
              • A Adno

                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.

                M Offline
                M Offline
                Moak
                wrote on last edited by
                #7

                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

                Home page

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups