Jump to content

TCP connection not receive all data?


Recommended Posts

Hey all, I'm new to these forums and need some help!

My IRCbot project has a few flaws already.

- multi-line IRC data seems to get packed in one variable (I need one line in the variable, could use a split and needs more work)

- Looks like data is missing

Here is the main function.

Func MainLoop()
    ; Start The TCP Services
    ;==============================================
    TCPStartup()

    ; Connect to a server
    ;==============================================
    $IRCSock = TCPConnect(TCPNameToIP($cfg_server), $cfg_port)

    ; If the Socket creation fails, exit.
    If $IRCSock = -1 Then Exit

    ; Send User and Nick info, so the IRC server knows who you are
    IRCSend("USER " & $cfg_ident & " 8 * :" & $cfg_realname)
    IRCSend("NICK " & $cfg_nick)

    While 1
        ; Try to receive 2048 bytes of data
        ;----------------------------------------------------------------
        $recv = TCPRecv($IRCSock, 2048)

        ; If the receive failed with @error then the socket has disconnected
        ;----------------------------------------------------------------
        If @error Then ExitLoop

        ; Check if there is some data, then show it. And if it is any usefull, use it!
        ;----------------------------------------------------------------
        If $recv <> "" Then
            ConsoleWrite("[IN]: " & $recv)

            If StringLeft($recv, 6) = "PING :" Then
                IRCSend("PONG :" & StringRight($recv, 6))
            EndIf
        EndIf
    WEnd

    TCPShutdown()
EndFunc   ;==>MainLoop

But when I run it, it doesn't seem to get it first Ping? Pong! event.

[OUT]: USER hhh 8 * :ohlawd
[OUT]: NICK pooppenis
[IN]: :some.irc.server NOTICE AUTH :*** Looking up your hostname...
:some.irc.server NOTICE AUTH :*** Found your hostname (cached)
[IN]: ERROR :Closing Link: [111.111.111.111] (Ping timeout)
+>AutoIT3.exe ended.rc:0

While this should happen:

-> USER hhh 9 * :ohlawd
 -> NICK pooppenis
 <- :some.irc.server NOTICE AUTH :*** Looking up your hostname...
 <- :some.irc.server NOTICE AUTH :*** Found your hostname (cached)
 <- PING :2E9F0472
 -> PONG :2E9F0472
 <- :some.irc.server 001 pooppenis :Welcome to the SomeNet IRC Network pooppenis!hhh@cool.hostname.com

So, why does '$recv = TCPRecv($IRCSock, 2048)' sometimes put those 2 lines in the same variable?

And why doesn't it receive the incoming PING :ASFSDDF?

// Thanks, The Dominance

Also, if this code inspired you or you just want to use/steal it, go ahead. :)

Edited by thedominance
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...