Sponsored Content
Top Forums Programming Cloning a socket connection, using other port numbers Post 302149766 by jonas.gabriel on Friday 7th of December 2007 09:13:03 AM
Old 12-07-2007
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
 

10 More Discussions You Might Find Interesting

1. Programming

socket on serial port

Does anyone know if it's possible to send socket by a serial port ? If yes, how can I find on Irix the value of my serial ports to use with this function : serverSockAddr.sin_port = ? Thanks for all responses ! Kintoo (2 Replies)
Discussion started by: kintoo
2 Replies

2. UNIX for Dummies Questions & Answers

Socket programming:One server two port

I want my server socket to listen on two ports in my machine. How do i achieve it? I will have two clients one connecting to 1 port and another to a different port. So my server needs to listen to both. Thanks. (1 Reply)
Discussion started by: abc.working
1 Replies

3. Programming

Socket Programming - Port Scanner. I Get Connection Timed Out, Why?

When i put the target IP as 127.0.1.1, the program is working fine, can catch blocked & open ports. But when i try to scan remotely, i get connection timed out! Can you tell me why? :( Here is my code - Look at between where i put astriks - at the bottom: #include<iostream>... (3 Replies)
Discussion started by: f.ben.isaac
3 Replies

4. Programming

Problem with socket connection

I have a client /server file operation program.It works properly when i run the client and server program in the same system.but when i try to run the client in one system and server in another system i am getting an error in the cleint machine as "ERROR:Connection refused". Plz help me in this ... (1 Reply)
Discussion started by: vigneshinbox
1 Replies

5. UNIX for Dummies Questions & Answers

permission to bind a socket to port 843?

I have written a flash socket security file server in PHP. The basic idea is that when Flash Player connects via socket to a server, the first thing it does is connect to port 843 and send a request for a 'socket policy file' by sending the string <policy-file-request/>. The problem I have is... (5 Replies)
Discussion started by: sneakyimp
5 Replies

6. Programming

doing a socket connection using ssh service

Trying to establish a socket connection using ssh service - but want to use different login name for ssh than what currently logged in as - if under shell know to use ssh -l <login-name> host - however - not sure how to tell o.s. to use different login name when use connect command (2 Replies)
Discussion started by: clcoh11
2 Replies

7. Programming

Using socket to test a TCP port

Hello, I'm trying to write a small c application to test a tcp port. This works fine for the most part but the default timeout on the connect is very long. I have been reading many posts but and it looks like I need to set the socket to be non-blocking and poll for a result. I have been totally... (2 Replies)
Discussion started by: tjones1105
2 Replies

8. Programming

socket programming using UDP connection

I want to send packets through single socket() but using two different port numbers in UDP. Anybody give some idea on this. Thanks in advance.:) (2 Replies)
Discussion started by: naresh046
2 Replies

9. IP Networking

Get process id and port from the socket

Hello, Please help me in getting the process id and the port number from the socket netstat -Aan|grep -i closed f100050010b133b8 tcp 0 0 *.* *.* CLOSED f1000500119b53b8 tcp4 0 0 *.* *.* ... (3 Replies)
Discussion started by: Vishal_dba
3 Replies

10. AIX

Process on a specified Terminal and Socket Port does not start

Hi, I new to AIX, and I have been using Rocket UniData in it. I had to set up a Process for Data Exchange by assigning a unique Terminal and a Socket Port to that process. I ran the process for the first time and it was successful and after use I stopped the process. Now when I want to run it... (3 Replies)
Discussion started by: BejoyS
3 Replies
rpc_use_family_wk(3ncs) 												   rpc_use_family_wk(3ncs)

Name
       rpc_use_family_wk - create a socket with a well-known port for a remote procedure call (RPC) server (server only)

Syntax
       #include <idl/c/rpc.h>

       void rpc_$use_family_wk(family, ifspec, sockaddr, slength, status)
       unsigned long family;
       rpc_$if_spec_t *ifspec;
       socket_$addr_t *sockaddr;
       unsigned long *slength;
       status_$t *status;

Arguments
       family	      The  address  family  of the socket to be created.  This value corresponds to the communications protocol used to access the
		      socket and determines how the sockaddr is expressed.  The value must be one of socket_$unspec or socket_$internet.

       ifspec	      The interface that will be registered by the server.  Typically, this parameter is the interface if_spec	generated  by  the
		      NIDL compiler from the interface definition; the well-known port is specified as an interface attribute.

       sockaddr       The socket address of the socket on which the server will listen.

       slength	      The length, in bytes, of sockaddr.

       status	      The  completion status.  If the completion status returned in is equal to status_$ok , then the routine that supplied it was
		      successful.

Description
       The routine creates a socket that uses the port specified through the if_spec parameter.  Use this routine to create a  socket  only  if  a
       server must listen on a particular well-known port.  Otherwise, use

       A  server  listens  on one socket per address family, regardless of how many interfaces that it exports.  Therefore, servers that use well-
       known ports should make this call once per supported address family.

Examples
       The following statement creates the well-known socket identified by for an array processor server:
       rpc_$use_family_wk (socket_$internet, &matrix$if_spec,
			      &sockaddr, &slen, &status);

Diagnostics
       This section lists status codes for errors returned by this routine in

       rpc_$cant_create_sock
			   The RPC runtime library was unable to create a socket.

       rpc_$not_in_call    An internal error.

       rpc_$proto_error    An internal protocol error.

       rpc_$too_many_sockets
			   The server is trying to use more than the maximum number of sockets that is allowed; it has called or too many times.

       rpc_$bad_pkt	   The server or client has received an ill-formed packet.

       rpc_$addr_in_use    The address and port specified in an routine are already in use.  This is caused by multiple calls  to  with  the  same
			   well-known port.

Files
See Also
       intro(3ncs), rpc_use_family(3ncs)

															   rpc_use_family_wk(3ncs)
All times are GMT -4. The time now is 11:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy