By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,713 Members | 764 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,713 IT Pros & Developers. It's quick & easy.

Transfer socket connection between programs

P: n/a
Does anyone know any method to have one program, acting as a server
transfer a socket connection to another program? I looked into
transferring the connection via xml rpc to no avail. It seems to be a
problem of getting access to a programs private memory space and
giving another program access to that space.

Thanks in advance,
James Howard

Nov 12 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
On 2007-11-12, JamesHoward <Ja************@gmail.comwrote:
Does anyone know any method to have one program, acting as a
server transfer a socket connection to another program?
The only way I know of is to use fork. When you fork a
process, all open file-descriptors (including network
connections) are inherited by the child.
I looked into transferring the connection via xml rpc to no
avail.
I've no idea how that could work (even in theory) on any OS
with which I'm familiar.
It seems to be a problem of getting access to a programs
private memory space and giving another program access to that
space.
Private memory has nothing to do with it. The connection is a
data structure that lives in kernel space, not in user space.
Even if you could grant another process access to your "private
memory space", it wouldn't help you "transfer a socket
connection", since that connection is something the OSes
manages.

--
Grant Edwards grante Yow! ! Everybody out of
at the GENETIC POOL!
visi.com
Nov 12 '07 #2

P: n/a
JamesHoward <Ja************@gmail.comwrites:
Does anyone know any method to have one program, acting as a server
transfer a socket connection to another program? I looked into
transferring the connection via xml rpc to no avail.
You have to use an out of band communication mechanism. On Linux this
is the SCM_RIGHTS ancillary message over Unix domain sockets. There
are similar things for Solaris and Windows. Unfortunately, Python
doesn't support any of them at the moment, but there's was once an RFE
waiting for a patch:

http://mail.python.org/pipermail/pyt...er/020431.html

Actually I'm having trouble finding the RFE mentioned any more, but it
it looks like Heiko Wundram did a patch in a different item:

http://bugs.python.org/issue1194378

See also:

http://bugs.python.org/issue1492240
Nov 12 '07 #3

P: n/a
On Nov 12, 12:50 pm, Grant Edwards <gra...@visi.comwrote:
On 2007-11-12, JamesHoward <James.w.How...@gmail.comwrote:
Does anyone know any method to have one program, acting as a
server transfer a socket connection to another program?

The only way I know of is to use fork. When you fork a
process, all open file-descriptors (including network
connections) are inherited by the child.
I looked into transferring the connection via xml rpc to no
avail.

I've no idea how that could work (even in theory) on any OS
with which I'm familiar.
It seems to be a problem of getting access to a programs
private memory space and giving another program access to that
space.

Private memory has nothing to do with it. The connection is a
data structure that lives in kernel space, not in user space.
Even if you could grant another process access to your "private
memory space", it wouldn't help you "transfer a socket
connection", since that connection is something the OSes
manages.

--
Grant Edwards grante Yow! ! Everybody out of
at the GENETIC POOL!
visi.com
Thanks Grant,

Does this mean that there is some way to transfer a pointer to that
kernel memory space from one program to another and have it be valid,
or is that kernel memory space protected and unusable from other
processes?
Nov 12 '07 #4

P: n/a
On 2007-11-12, JamesHoward <Ja************@gmail.comwrote:
>Private memory has nothing to do with it. The connection is a
data structure that lives in kernel space, not in user space.
Even if you could grant another process access to your "private
memory space", it wouldn't help you "transfer a socket
connection", since that connection is something the OSes
manages.
Does this mean that there is some way to transfer a pointer to that
kernel memory space from one program to another and have it be valid,
No.
or is that kernel memory space protected and unusable from other
processes?
On Linux (I'm not sure how it works on Windows), there is a
table of file descriptors that the kernel keeps for each
process. A table entry can be an open file on disk, a serial
port, a network connection, etc.

A file descriptor is just an index into that table. That table
can't be accessed by any other processes. When you fork a
process the new process inherits a copy of that table (and
therefore inherits any open network connections).

--
Grant Edwards grante Yow! I'm having an
at EMOTIONAL OUTBURST!! But,
visi.com uh, WHY is there a WAFFLE
in my PAJAMA POCKET??
Nov 12 '07 #5

P: n/a
JamesHoward wrote:
Does anyone know any method to have one program, acting as a server
transfer a socket connection to another program? I looked into
transferring the connection via xml rpc to no avail. It seems to be a
problem of getting access to a programs private memory space and
giving another program access to that space.
If you are using UNIX, you can create a pipe in the filesystem, and
connect I/O on both ends. Of course this is not the same, because - for
example - you cannot use setsockopt. But it works with already existing
processes very well, and usually you can setup socket options in your
server.

Under windows, I have no clue. It may be possible to use pipes under
Windows but I don't know how. You can also use other nasty techniques,
like loading a DLL into your "another program", then make a code hook
into your server. Brrrrrrr. :-) (Unstable, not portable even between
Windows versions...)

Regards,

Laszlo
Nov 12 '07 #6

P: n/a
JamesHoward napisa (a):
Does anyone know any method to have one program, acting as a server
transfer a socket connection to another program? I looked into
transferring the connection via xml rpc to no avail. It seems to be a
problem of getting access to a programs private memory space and
giving another program access to that space.

Thanks in advance,
James Howard
Under Windows you may want to use WSADuplicateSocket WinAPI function +
a named pipe (for example) to transfer the obtained socket data from
one process to the other.

Hope that helped,
Marek

Nov 12 '07 #7

P: n/a
On Nov 12, 1:41 pm, JamesHoward <James.w.How...@gmail.comwrote:
Does anyone know any method to have one program, acting as a server
transfer a socket connection to another program? I looked into
transferring the connection via xml rpc to no avail. It seems to be a
problem of getting access to a programs private memory space and
giving another program access to that space.

Thanks in advance,
James Howard
On Unix, you can use Unix Domain Sockets to pass file descriptors
between processes. You need to create a Unix Socket, then use sendmsg
and recvmsg to pass the file descriptor between processes.

Linux Application Development includes an example of how to do this in
section 16.4.6. The book is available through Amazon.com at
http://www.amazon.com/Linux-Applicat.../dp/0321219147

I'm sure you can find other examples on the internet to follow.

Hope this points you in the right direction,

--Nathan Davis

Nov 12 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.