The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
Socket Module Implementation
Discuss Socket Module Implementation in the Python Programming forum on Dev Shed. Socket Module Implementation Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 5th, 2004, 12:07 PM
|
|
Contributing User
|
|
Join Date: Apr 2004
Location: Canada
Posts: 242
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
|
|
|
Socket Module Implementation
When looking in the socket module code the first comment reads:
Code:
# Wrapper module for _socket, providing some additional facilities
# implemented in Python.
Does anyone know where _socket is?
Also, is it possible to write a lower level socket module?
|

June 5th, 2004, 12:44 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
Under windows i'd assume it were in the DLL folder within Pythons main directory. If you do a search for _socket.pyd then you should find it  .
The socket module is a wrapper over that defined by C/C++ so i would highly dout it although if you look into how C/C++ implements this then maybe...
Mark.
__________________
programming language development: www.netytan.com – Hula
Last edited by netytan : June 5th, 2004 at 12:47 PM.
|

June 5th, 2004, 02:57 PM
|
 |
Only the strong survives!!.
|
|
Join Date: Feb 2003
Location: A World of wonders.
|
|
Quote: | Originally Posted by NetBSD When looking in the socket module code the first comment reads:
Code:
# Wrapper module for _socket, providing some additional facilities
# implemented in Python.
Does anyone know where _socket is?
Also, is it possible to write a lower level socket module? |
socket is a low level socket with blocking
|

June 6th, 2004, 01:41 PM
|
|
Contributing User
|
|
Join Date: Apr 2004
Location: Canada
Posts: 242
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by netytan Under windows i'd assume it were in the DLL folder within Pythons main directory. If you do a search for _socket.pyd then you should find it  . |
Weird... it doesn't find it?
|

June 6th, 2004, 01:44 PM
|
 |
Hello World :)
|
|
Join Date: Mar 2003
Location: Hull, UK
|
|
|
Mmm, thats strange. Does the socket module import properly. You might also want to try searching for _socket.dll though it should b _socket.pyd by convention.
Mark.
|

June 6th, 2004, 03:32 PM
|
|
Contributing User
|
|
Join Date: Apr 2004
Location: Canada
Posts: 242
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
|
|
Code:
[Aurora:~] chris% python
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> sock = socket.socket()
>>> sock
<socket._socketobject object at 0x538a0>
>>>
I'm on Mac OS X, so it wouldn't be .dll. I just searched for "_socket" and it found nothing. I downloaded the 2.3.4 source and I can't find it in there either.
|

June 6th, 2004, 04:22 PM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
Let's say you can import _socket (you should be able to):
Code:
>>> import _socket
>>> print _socket.__file__
You should get the implementation file.
Of course, this is nicer and works with many more objects:
Code:
>>> import inspect
>>> import _socket
>>> print inspect.getfile(_socket)
|

June 6th, 2004, 05:13 PM
|
|
Contributing User
|
|
Join Date: Apr 2004
Location: Canada
Posts: 242
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
|
|
Code:
[Aurora:~] chris% python
Python 2.3 (#1, Sep 13 2003, 00:49:11)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import _socket
>>> print _socket.__file__
/System/Library/Frameworks/Python.framework/Versions/2.3/lib/python2.3/lib-dynload/_socket.so
This seems to point me to the shared library. Do you know where I can get the Python source for it (_socket is written in Python, isn't it?)?
|

June 6th, 2004, 05:20 PM
|
|
Contributing User
|
|
Join Date: Jul 2003
Posts: 133
Time spent in forums: < 1 sec
Reputation Power: 10
|
|
|
No. The _socket module is not written in Python. It's written in C.
You can find the wrapper source in Python-Src/Modules/socketmodule.c and the header file in Python-Src/Modules/socketmodule.h.
|

June 6th, 2004, 06:33 PM
|
|
Contributing User
|
|
Join Date: Apr 2004
Location: Canada
Posts: 242
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
|
|
|
Sorry to drag this on longer, but I just need one more clarification: Does socketmodule.c wrap _socket (socket->sockmodule->_socket) or is socketmodule.c the file for _socket?
Bah... I don't even understand how Python can import a C file...
|

June 6th, 2004, 09:09 PM
|
|
Contributing User
|
|
Join Date: Dec 2001
Location: Houston, TX
Posts: 383
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 12
|
|
|
The better question is - what do you need a lower level socket for?
|

June 7th, 2004, 09:53 AM
|
|
Contributing User
|
|
Join Date: Apr 2004
Location: Canada
Posts: 242
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
|
|
|
For fun?
|

June 7th, 2004, 11:25 AM
|
|
Contributing User
|
|
Join Date: Dec 2001
Location: Houston, TX
Posts: 383
Time spent in forums: 1 h 41 m 27 sec
Reputation Power: 12
|
|
|
But what exactly would you need to make it a lower-level one? The socket module provides you pretty much the same control over sockets as the equivalent C socket library would. In other words, they are already fairly low-level in that you have a good amount of control over them, but they are high-level in the respect that they are wrapped in a nice interface that you can easily use without a lot of setup.
|

June 7th, 2004, 12:49 PM
|
|
Contributing User
|
|
Join Date: Apr 2004
Location: Canada
Posts: 242
Time spent in forums: 11 h 3 m 17 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by Strike But what exactly would you need to make it a lower-level one? The socket module provides you pretty much the same control over sockets as the equivalent C socket library would. In other words, they are already fairly low-level in that you have a good amount of control over them, but they are high-level in the respect that they are wrapped in a nice interface that you can easily use without a lot of setup. |
I'm interested in low-level stuff (don't tell me to "use C then", because I already do  ). Although, it was the actual implementation of the socket module for Python that interested me, and writing it over again would be a waste so the alternative was to write a lower level one.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|