The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Error: No Route to host...urgent {socket() connection} arunchaudhary19 High Level Programming 6 10-30-2007 04:10 AM
Socket programming:One server two port abc.working UNIX for Dummies Questions & Answers 1 10-17-2007 12:32 PM
Session PID & socket connection pid pcx26 UNIX for Dummies Questions & Answers 1 03-30-2006 12:06 PM
[Problem]Reuse port in BSD socket Namely High Level Programming 1 11-28-2003 11:36 AM
socket on serial port kintoo High Level Programming 2 07-31-2001 03:44 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-07-2007
jonas.gabriel jonas.gabriel is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 17
Cloning a socket connection, using other port numbers

Hello everybody,

I've coded a multi-client server based on internet sockets using the scheme
listen on port X-accept-fork, exactly like beej's guide

At some point I would like to establish a secondary connection between a client and the server-child serving him.

I was considering the server-child bind() a socket to port X+1 listen() to it and then accept() a connect()ion by the client.But that can't be done, because if 2 server-children do that simultaneously, one would get "address already in use" error.

So then I've considered the client listen()ing on the Y+1 port (Y is the port assigned to the client's socket automatically by the primary connect() ).But my problem here is how can I find this port ? getpeername() on client's socket gives me the server's address & port.Is there any function giving the local address & port ?

I know that some problems remain. I am not guaranteed that port Y+1 is available.

A possible solution is that the client could send a free port number to the server through the primary connection and then the server-child connect()s to that port.

Or another one: The server-child knows the client's Y port when server-parent accepted() the connection.So server-child could send it back to the client.

But these aren't elegant solutions.Have you any ideas or suggestions?

Thank you
  #2 (permalink)  
Old 12-08-2007
sonicx sonicx is offline
Registered User
  
 

Join Date: Aug 2007
Posts: 9
well, to me that sounds all a bit complicated. why not accept new connections on one specified port,then if a client wants another connection, it just asks at that same port again. if a connection is accepted it gets it own socket. there is no need to chose a port for every connection the server gets in. if you have to choose ports within the client, just do it randomly above 1024 and retry if one wont open.

Last edited by sonicx; 12-08-2007 at 08:59 AM.. Reason: typos
  #3 (permalink)  
Old 12-09-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Have a look at how the FTP protocol does this, then look at the problems this causes and why it's not simple how FTP traverses firewalls.
  #4 (permalink)  
Old 12-10-2007
DreamWarrior DreamWarrior is offline
Registered User
  
 

Join Date: Oct 2003
Posts: 70
For what reason do you need a secondary connection when you already have a pefectly good established connection between the client and server?
  #5 (permalink)  
Old 12-10-2007
porter porter is offline Forum Advisor  
Registered User
  
 

Join Date: Jan 2007
Posts: 2,965
Another couple of examples

(a) X's DISPLAY environment variable, where the host and port are encoded in a single string (port = display+6000)

(b) CORBA, where an IOR contains hostname and port

Both of these have problems when it comes to firewalls, the best solution for X for instance is using Xnest to proxy the display on the far side of the firewall.

CORBA introduced bidirectional-IOP to help solve the firewall-traversal problem by attempting to reuse existing connections.
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 03:54 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0