See also
Here is a short description of how to use the wxchat program along with screen shots from the program.
When the program is first loaded, the user sees a Server pull down menu at the top and two buttons at the bottom of the window.
If the server is running on localhost or the user specified a server name on the command line when wxchat was started, they are ready connect to the server.
The Server pull down menu can be used to set or change the host name of the server.
Once the chat client knows how to find the server, the user may click on Connect and begin talking to whom ever is also connected to the server. They can set the name that they want to go by while chatting by entering a name and cliking on the Set Nick Name button. To send a message, they just type the message in the lower text window and either press the Enter key or click on the send button.
Messages that the user has typed appear in the middle window and messages received from the server appear in the upper window.
If the user needs to step away for a short time, they can click on the Be Right Back button. Entering a message before clicking on Be Right Back is optional.
No messages are sent to the client while they are away and the buttons change to indicate their status as being away.
After they have returned, they click on the I’m Back button to resume the chat session. Typing a message to go with I’m Back is optional.
This is an example of what another user will see when someone else is away and later returns.
Here is a little bit of documentation about the more important functions and classes from the wxchat program. This documentation is auto-generated from the Python source code and doc strings contained in the source code.
File: wxchat.py
The client application (with GUI) to go along with the chat server. wxchat Requires wxPython.
Copyright 2009, Tim Bower: Apache Open Source License
The main class containing the wxPython graphical interface.
File: rendezvous.py
A couple functions in a class just to facilitate communication between the networking thread and the main thread which does the graphics. Basically, the only purpose of these functions is so that the code that does the networking does not have to know anything about how the graphics are done (wx, TK, ...). Having this in a separate file also helps with imports so that there is not an import loop between the graphics and networking.
When used with wxPython, We just use the wx.CallAfter() function to send data from the networking thread to the wxFrame in the main thread.
If used with TKinter graphics (a previous implementation), we have to use a queue and generate new events on our own – much more complicated.
Messages from the networking thread get left here and the appropriate wxPython events are generated to notify and pass data to the graphics thread.
File: chatnetwork.py
The networking portion of chat room client. Most of this runs in a separate thread from the main thread which manages the graphical interface. See wxchat.py
Copyright 2009, Tim Bower. Apache Open Source License
Run as a separate thread to make and manage the socket connection to the chat server.
Here is a little bit of documentation about the more important functions and classes from the chat server program. This documentation is auto-generated from the Python source code and doc strings contained in the source code.
File: chatserver.py
Chat Server with Threading
Copyright 2009, Tim Bower: Apache Open Source License
| Parameters: |
|
|---|
This computes the index value of the message queue from where the reader should return messages. It accounts for having a cyclic counter. This code is a little tricky because it has to catch all possible combinations.
Manage a queue of messages for Chat, the threads will read and write to this object. This is an implementation of the readers - writers problem with a bounded buffer.