|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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? |
|
#2
|
||||
|
||||
|
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. Last edited by netytan : June 5th, 2004 at 12:47 PM. |
|
#3
|
||||
|
||||
|
Quote:
socket is a low level socket with blocking
__________________
IE QUOTE | PHP Manual | Google | C/C++ Compiler | Linux Tutorials | General Stuff Game Dev |
|
#4
|
|||
|
|||
|
Quote:
Weird... it doesn't find it? |
|
#5
|
||||
|
||||
|
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. |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
|||
|
|||
|
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) |
|
#8
|
|||
|
|||
|
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?)? |
|
#9
|
|||
|
|||
|
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. |
|
#10
|
|||
|
|||
|
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... |
|
#11
|
|||
|
|||
|
The better question is - what do you need a lower level socket for?
|
|
#12
|
|||
|
|||
|
For fun?
|
|
#13
|
|||
|
|||
|
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.
|
|
#14
|
|||
|
|||
|
Quote:
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. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > Socket Module Implementation |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |