Project 5 — Chat
Requirements (100 points)
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:
- A way to specify the IP address of the computer to connect to
- A text box for entering messages to send
- A display that shows the conversion
- A menu bar that contains ways to: exit, open an About Box with information about the app, and an options window that lets the user set font face, color, and size of the text
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:- Download IronPython here. Then extract the contents of this folder to somewhere you can find it.
- To be able to launch IronPython from any directory in the command prompt, you'll need to add the location of ipy.exe.
- To do this, right-click on My Computer and look for System Properties or Advanced Settings. On the Advanced tab, click the Environment Variables button.
- Find, or create, the Path variable for either just your user account or the entire system.
- Edit the Path variable by appending to the end of it ;IPYDIR, where IPYDIR is the location of the folder containing ipy.exe.
- Next time you launch command prompt, you should be able to run ipy from anywhere.
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:
- Python is a dynamic language, so there is no static typechecking. Therefore variables are not declared with a type; they take on specific types at runtime. That means typing errors in your code will get snagged at runtime, not compile time.
- There are no braces around code blocks. On the other hand, whitespace is important, ie, code blocks are distinguished by the amount of indendation. You don't have to use tabs, but your spacing has to be consistent for a given block. Also, semi-colons are not required.
- When instatiating an object, there is no new keyword.
- self is the equivalent of this.
- None is the equivalent of null.
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.