Python – How to write an optimal LAN messenger software

pythonwindowswindows 7

I am asking this question as an extension to the following question:
https://superuser.com/questions/713409/how-to-message-any-user-on-your-lan

I don't think I have a real answer. I found it quite difficult to get the net send command working on Windows 7 and even if I could have it would have been enabled only for admin users.

So I have decided to write my own program to solve the problem. Using python I can write a program to check for messages on a common file (which I can store on a common harddrive which we have on our LAN). So the program will write from:192.168.23.44 to:192.168.23.45 Hello. Assuming the program is installed on both machines, I can ask the machines to poll this file every few seconds and pop-up a message if a message has been written for it, by searching for it in the to: field. If writing to a single file becomes an issue I will make multiple files which will act as inboxes for each of the computers on the LAN.

However, this approach is very inelegant. I don't suppose internet messengers, Google talk for instance, poll a server to check whether there are any new messages for the user. So my question is: what is the optimal way to write a LAN messenger program. Now that I think of it, I am looking for a minimalist approach. I will just put the program in the Startup folder of all the machines and it should come alive whenever any user logs in.

I was just able to configure the machine to respond to the ping command by making a new rule for the ICMPv4 protocol (ref: http://answers.microsoft.com/en-us/windows/forum/windows_7-networking/how-to-enable-ping-response-in-windows-7/5aff5f8d-f138-4c9a-8646-5b3a99f1cae6). I am guessing that answer lies in python and the ICMPv4 protocol, but I needed some direction.

Best Answer

You could create your own chat protocol based on TCP/IP sockets.

There are two common ways to implement such an application. Either a client/server architecture or a peer-to-peer architecture.

In the client/server architecture, you run a central chat server on a machine which is always on. Each participant uses a separate client application. When a client goes online, it connects to the server. When a client want to send a message, it sends that message to the server. The server then relays it to the recipient(s).

When you don't have a server which is always online, you could instead go for a peer-to-peer architecture.

In that scenario your chat program is both client and server at the same time. To send a message to another user, the client of the sender connects directly to the client of the receiver. In order to be able to do this, you need to know the receivers IP address or at least its hostname so you can resolve the IP through DNS.

Related Topic