Losing words

Chris Angelico rosuav at gmail.com
Mon Apr 1 15:41:01 EDT 2019


On Tue, Apr 2, 2019 at 6:36 AM John Doe <john at johniedoe.com> wrote:
>
> On 2019-04-01, Roel Schroeven <roel at roelschroeven.net> wrote:
> > This is what 'while' is made for:
> >
> > def text():
> >      while True:
> >          mess = input("> ")
> >          s.send(bytes("PRIVMSG " + " "+ channel + " " +  mess  + "\n",
> > "UTF-8"))
> >
>
>  see it working thanks, indeed while is powerful, had to add colon to be able send a whole string but can
>  get it working with other loop while 1, I tried many ways to implement
>  it together but either I cant send or receive and print data from
>  someone sending datas to channel.
>
> def text():
>     while True:
>         mess = input("> ")
>         print(mess)
>         s.send(bytes("PRIVMSG " + " "+ channel + " " + ":" + mess  + "\n", "UTF-8"))
>
> text()
>
> while 1:
>     data = s.recv(4096).decode('utf-8')
>     print(data)
>     if data.find('PING') != -1:
>         s.send(str('PONG ' + data.split(':')[1] + '\r\n').encode())
>         print('PONG sent \n')
>

Yeah, definitely get to know the protocol or get a library. You cannot
depend on a single socket read representing a single message. You'll
need to properly parse the incoming stream; otherwise, you'll run into
other problems, like "my messages don't work if two of them come in at
the same time". There are IRC libraries on PyPI.

ChrisA


More information about the Python-list mailing list