Re: Socket programming question.

From: PC (uri_at_ipdaily.org)
Date: 07/10/04


Date: Fri, 9 Jul 2004 23:51:44 -0700


You missed the part in the documentation that says, when an accept occurs,
it assigns a new port number and provides the connecting ip address, thus
the listen could be on port 80, but the link is random and could be on port
2112 or port 3022 as example.

The new socket also retains the `select' settings of the listen port, so if
you only set it for FD_ACCEPT | FD_CLOSE then the `select' settings need to
be redone for FD_READ and FD_WRITE

As example

WSAEventSelect(hSocket, hEvent, FD_READ | FD_WRITE | FD_CLOSE);

"John Sheppard" <John Sheppard@discussions.microsoft.com> wrote in message
news:ABE01BEF-1A38-4564-9551-43C7EC76C344@microsoft.com...
> Hi all,
> I am not sure that I am posting this in the right group but here it
goes anyway. I am new to socket programming and I have been searching on
the internet to the questions I am about to pose but have been unsuccessful
in finding the answers so far. Either because my understanding of sockets
isn't where it needs to be or my questions are to basic.
> My programming environment is Windows XP, Visual Studio .NET 2003 and
C#.
> So here it goes. I have been able to set up async sockets that listen
to a particulare port with Bind and Listen with the standard with
Socket.BeginAccept, Socket.BeginReceive, Socket.EndReceive, etc. etc. using
the ManualResetEvent to signal finished states. I am using a collection of
classes to hold connected sockets that are retreived on the call to
Socket.EndConnect. I understand how to do all this. Where my failure of
understanding comes in is when I want to send data. I want to send data
from the same socket that I am listening on. So let's say I have a class
that controls the starting and stopping of listening to a socket. This
class also has a custom generated class that is a collection of sockets
stored by the hash of the RemoteEndPoint that it is connected to. I first
check to see if the collection contains a current connection to the endpoint
that I want to send data to. If it does, grab that socket which is already
connected and do a BeginSend on it with the data I want to send. Here is
where I get confused. If a socket with the endpoint that I want to send to
does not exist, I want to connect to a remote system using the port of the
socket that I am currently listening on. Either using the blocking Connect
or the async BeginConnect When I attempt to do this I get a
System.SystemException {"An invalid argument was supplied"}. Now if I
create a new socket with the same AddressFamily, etc and do a connect, it
picks up a new port to send on. I understand that this is an option but not
the option that I want.
> What am I overlooking or misunderstanding here? The reason why I want
to connect from a specific port is because I am writing a P2P app that
tracks all clients by a given address and port. If my approach is not valid
I am going to have to drop back, punt and rethink.... :).
> Thanks for any/all help that you may be able to provide.
>
> John



Relevant Pages

  • Re: SetSockOpt with SO_REUSEADDR parameter
    ... So I create multiple UDP sockets with the same port to send data. ... happening is that you are throwing away the old socket and replacing it with the new ... When the second client is connecting to server, I still get the error code ...
    (microsoft.public.vc.mfc)
  • Re: REMOTE DESKTOP NOT WORKING ANY LONGER PLEASE HELP!
    ... Yes the host is listening on port 3389 the default and I verified this. ... Try connecting again. ...
    (microsoft.public.windows.terminal_services)
  • socket connection problem between C++ ActiveX and C# listening port
    ... I don't know if there is discrepancy between straight C code socket ... Few years ago I wrote an ATL ActiveX and a C++ daemon running locally ... The daemon opens a port on "localhost" and listens ... and send messages to the listening daemon. ...
    (microsoft.public.pocketpc.developer)
  • Re: Socket and cycle problem
    ... listening this port countinously. ... So I need make some loop to print data from 3883 port permanent. ... the data it receives from each connection after the remote side drops ... If you were to use the socket module, then it would look something like this: ...
    (comp.lang.python)
  • Re: help need in chat client/server
    ... Im new to this network programmin and I need help with this code i ... require "socket" ... PORT = 12321 ... listening but the sending end never listens and the listening end never ...
    (comp.lang.ruby)

Loading