COM Sockets

David Fisher python at
Tue May 9 23:45:53 EDT 2000

----- Original Message -----
From: "Rafferty" <rafferty at>
Newsgroups: comp.lang.python
To: <python-list at>
Sent: Wednesday, May 03, 2000 4:31 PM
Subject: COM Sockets

> I am trying to establish a socket from Excel using COM python code.  I
> started with the sample code and tried enclosing it in COM but when I
> execute I get a socket error 10061.  Any ideas I want to use COM to send
> data from Excel or Word to a socket server for testing.
[snip code]

I tried your COM server and it worked fine for me (after demangling the
whitespace).  I called your server from Excel and had it put the results in
the button caption.  I was running both the server and Excel on the same
machine, but I can see no reason it shouldn't work across the network.

My VBA code is something like (from memory, please ignore typos):

Sub CommandButton1_Click
socsrv = CreateObject("ICE.COMUtilities")
CommandButton1.Caption = socsrv.COMCreateSocket()
End Sub

I wrote a simple threaded echo server.  This code is tested:

from socket import *
import thread

def child(s):
    while 1:
        data = s.recv(1024)
        if not data:

def main():
    so = socket(AF_INET,SOCK_STREAM)
    while 1:
        conn,addr = so.accept()
        print `addr`

if __name__ == '__main__':

I used port 4000 out of habit, and changed only that in your COM server.

More information about the Python-list mailing list