#๐Ÿ”’ IRC client library either does not actually send messages, or doesn't receive responses

22 messages ยท Page 1 of 1 (latest)

left mapleBOT
#

@clever swan

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

clever swan
#

Worth noting that I have an IRC client monitoring the IRCd and the channel #test, nothing appears on that client's end when the test client is ran

opaque pulsar
#

is it possible you're missing the \r\n after each line?

clever swan
#

Do I actually have to send a CRLF after each line?

opaque pulsar
#

yes

#

otherwise they get all treated as one single line

clever swan
#

Well I'll be damned, that did something

opaque pulsar
#

TCP is a stream.

#

with TCP you have to always assume, that you might not receive the complete data, or sometimes multiple pieces of data are merged

#

(hough you're using readline(), so that's doing it for you automatcally.)

clever swan
#

Hm, the servers sending :localhost.com 451 TestNyte_ :You have not registered

opaque pulsar
#

not sure what thath means. are you using one of those NickServ services? Or maybe the USER command did not work?

clever swan
#

Perhaps it's because the PASS being sent is nonsensical with an anonymous user

opaque pulsar
#

it's been a while since I last used IRC ๐Ÿ˜„ (aside from twitch chat)

#

possibly

clever swan
#

Ah lovely it works now

#

Had to fix the PONG response and actually set up the client password to comply with how I set up the IRCd

opaque pulsar
#
    async def _loop(self):
        buf = b''
        while True:
            data = await self._reader.readline()
            if not data:
                print('Connection closed')  # no data = EOF
                break

            # collect all data in a buffer
            buf += data.replace(b'\r', b'\n')  # now we only need to deal with \n

            while b'\n' in buf:
                # split out a line and keep the rest in buf (maxsplits+loop condition ensures there will be exactly two elements)
                line, buf = buf.split(b'\n', maxsplits=1)
                if line.startswith(b'PING '):  # respond with the exact same message, but as PONG
                    await self.send(line.replace(b'PING', b'PONG', 1) + b'\r\n')
                    continue

                plaintext = line.decode('utf-8')  # this might still fail, as IRC doesn't define any encoding
                logging.debug(f"Received: {plaintext}")
                yield line

    async def mainloop(self):
        async for line in self._loop():
            print(line)


``` here a sample of how to do it if you can't use .readline() ๐Ÿ˜„
(plus an example how to yield your lines in an async for loop)
#

you might eant to add a "sendline" method, and use that one for everything instead instead.

left mapleBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.