Project 5 — Chat

Requirements (100 points)

Your task is to implement a simple peer-to-peer chat application in IronPython.

User Interface

There is a minimal number of components you must provide, and you may design the UI in a way you think is fit:

Functionality

You application needs to support only one connection at a time.

You will use establish a TCP socket to communicate with another computer running your app. The example provided below shows a way of setting up this communication channel. Note that any instance of your application is able to attempt to connect to another computer and also listen for incoming requests. You can choose an arbitrary port to use for your application; something large like 2000 or higher is a fine choice.

When a connection has been made, communication between the two parties in any order must be allowed. You will need to use a separate thread to listen for input while also allowing the local user to compose and send messages.

The font settings the user selects should be saved for the next time the program is run. You can choose how to save and load these settings.

Resources

To get IronPython up and running:

Here is a sample app that demonstrates some basic use of WinForms in IronPython. From the command prompt navigate to the folder where you've saved demoform.py and run ipy demoform.py.

Here are a sample server and client. Like the example we saw in class, the server simply waits and echoes whatever the client sends it. Run ipy demoechoserver.py from one command prompt shell and ipy demoechoclient.py from another.

There is IronPython integration with Visual Studio, but I have not tried it. You can find info about it here. Or you can just write your code the hard way -- with a plain text editor with (gasp) no IntelliSense. =)

Python is an easy language to pick up and you won't need to learn much syntax for the assignment at hand. The tutorial on the Python website is a good reference for looking up specific language features. A couple of things to keep in mind:

Note about threading: I have not found any way to define a delegate type directly in IronPython, so a way to get around this is to define your delegate type in C#, compile that DLL, and import that DLL from your IronPython program. So defining a class library DelTest.dll that contains a delegate type with the signature public delegate void MyDel(string s); allows you to use this delegate type in IronPython as in this sample. This sample uses the same pattern for safely updating the UI across threads that we saw before.