January 26th, 2004, 05:34 PM
Stupid IO question
So I'm in the middle of writing a decentralized file-sharing program in Python. So far I've written code to manage connections to users, maintain a routing table, and send/receive data. To make sure all this code works, I'd first like to use it to make a chat program. A very basic one.
Basically, my question is if I can do a chat program using just a prompt, and no fancy GUI? I expect it would use two threads: The first would wait for a command from the user (of the form something like "<person to message> <message>"). The second would be responsible for sending messages you create and receiving messages for you. But it's also responsible for routing messages passing through you (since it is a decentralized network, messages may pass through you that are not intended for you -- your job is simply to pass them along so that they reach their destinations), so this thread must never sleep. So even while the first thread is waiting for user input, this thread must be active, enabling communication between users.
Now say this second thread, which sends and receives messages, receives a message intended for the user. It needs to display it to the screen -- but would this interfere with the first thread, which is waiting for user input? What if the client received a message and chose to display it to the screen while the user is typing in a message to send to another user? The result could be ugly. Any way to avoid this interference?
The obvious solution is a GUI... One window, two text boxes -- one in which you can type messages to send, and one which displays messages you receive. But in all honesty I don't have much time to learn wxPython right now (I will in a week or so...) -- unless anyone can point me to a, say, really skimpy wxPython tutorial
Sorry if this post is so longwinded. Kinda tired.
January 26th, 2004, 05:39 PM
If all you are doing this for is a test of the communications, why don't you just write the recieved text to a text file? You can just keep reloading it to see when you get data.