Hey, all!

I'm new here, and needed somewhere to get an answer dealing with Python.

I am working on developing a small bit of code, but I don't know where to start. I'm kinda new to python : (

I am looking to deveolop an Instant messenger sort of thing, just for use between me and a buddy.

I need to know if it's possible to develop a .py program that will connect to the internet to send and recieve information to a server?

I was thinking that if there was a way for python to add text to a html file on the server, then somehow show the html file IN the python screen? But if that's not possible, I have absolutely no idea where to even begin.

Any help is greatly appreciated!
--skate6566

First there are many very complete clients for instant messenging, like psi http://psi-im.org/ for example. Within minutes, you can be able to talk to your buddy privately on the internet, so the first question is do you really need to write your own instant messenger in python (knowing that you won't obtain the same quality as existing software without an enormous programming effort).

However, if you want to try, there are many ways for python to connect on the internet. The most basic way is to use socket objects defined in the standard socket module http://docs.python.org/lib/module-socket.html. See the basic examples here http://docs.python.org/lib/socket-example.html.

Connecting to a server using a socket is very easy:

import socket
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # create a socket object
sock.connect((HOST, PORT)) # connect to a host like '100.50.200.5' and a port like 9856
# use the socket to send and receive data
sock.close()

The socket object has 2 methods send and recv to send en receive messages through the connection. Observe that the connection uses an internet address, so you will have some problems if your internet addresses are dynamically allocated (by DHCP eg), because the address changes each time you reboot your modem or your computer.

As a first step for your project, you could write 2 programs: a server program which will open a socket on a port on your machine, and a client program for the remote machine which will connect to your server. Both program will exchange a few messages and print the messages they sent and received.

I think you should forget about your html features until you have a first version which runs for standard text in a console. Good luck ;)

You could easily display html using wxpython. Use the ActiveX_IEHtmlWindow from wx. The only problem I see is that your IM client will have to tell the difference between html and regular text. For that you make a protocol. Say the first 4 letters define what type of file it is. text would be text and the rest would be displayed on the screen. html would use the ActiveX_IEHtmlWindow.

Erik Anderson

This article has been dead for over six months. Start a new discussion instead.