Уведомления

Группа в Telegram: @pythonsu

#1 Июнь 20, 2009 11:54:35

Newbie
От:
Зарегистрирован: 2009-03-02
Сообщения: 19
Репутация: +  0  -
Профиль   Отправить e-mail  

How to make a simple command-line chat in Python?

I study network programming and would like to write a simple command-line chat in Python.

I'm wondering how make receving constant along with inputing available for sending at any time.

As you see, this client can do only one job at a time:

from socket import *

HOST = 'localhost'
PORT = 21567
BUFSIZE = 1024
ADDR = (HOST, PORT)

tcpCliSock = socket(AF_INET, SOCK_STREAM)
tcpCliSock.connect(ADDR)

while 1:
data = raw_input('> ')
if not data: break
tcpCliSock.send(data)
data = tcpCliSock.recv(BUFSIZE)
if not data: break
print data

tcpCliSock.close()
So if another client sends a message, this client will only receive it after sending a message too. I bet you understand me. I have googled for the matter and found out many interesting things such as asynchronous I/O, threading, non-blocking synchronization, concurrent programming and so on. I have also installed the twisted package. In brief, I've been learning all these things but yet haven't found what I was looking for. (Of course, I will keep trying and trying until I get to the point.)

So, my question is how make that? =)



Офлайн

#2 Июль 31, 2009 00:26:04

Ikinoki
От:
Зарегистрирован: 2009-07-30
Сообщения: 4
Репутация: +  0  -
Профиль   Отправить e-mail  

How to make a simple command-line chat in Python?

look into asyncore (it comes with base python)



Офлайн

Board footer

Модераторировать

Powered by DjangoBB

Lo-Fi Version