COM Sockets

David Fisher python at rose164.wuh.wustl.edu
Tue May 9 23:45:53 EDT 2000


----- Original Message -----
From: "Rafferty" <rafferty at aol.com>
Newsgroups: comp.lang.python
To: <python-list at python.org>
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:
            break
        s.send(data)

def main():
    so = socket(AF_INET,SOCK_STREAM)
    so.bind('',4000)
    so.listen(5)
    while 1:
        conn,addr = so.accept()
        thread.start_new_thread(child,(conn,))
        print `addr`

if __name__ == '__main__':
    main()

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





More information about the Python-list mailing list