G
Guest
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 too 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 and accept connections with Socket.BeginAccept and Socket.EndAccept. The class also listens with the Socket.BeginReceive and Socket.EndReceive functions. I also use the ManualResetEvent to signal finished states between the various async functions. I am using a custom developed collection class to hold connected sockets that are retreived on the call to Socket.EndConnect in the SocketConnectCallback function. 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 a listening socket. This class also has a custom developed 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 data 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, preferably the later. 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 BeginConnect, it picks up a new port and connects to the remote system and then I can send data on that socket. 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
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 too 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 and accept connections with Socket.BeginAccept and Socket.EndAccept. The class also listens with the Socket.BeginReceive and Socket.EndReceive functions. I also use the ManualResetEvent to signal finished states between the various async functions. I am using a custom developed collection class to hold connected sockets that are retreived on the call to Socket.EndConnect in the SocketConnectCallback function. 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 a listening socket. This class also has a custom developed 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 data 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, preferably the later. 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 BeginConnect, it picks up a new port and connects to the remote system and then I can send data on that socket. 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