N
Nak
Hi there,
After recently coming across issues with implementing a UDP server for
interprocess communication; involving file transfer, I have decided to go
onto TCP.
Now I *have* created a TCP server in the past for VB.NET but had
troubles when it comes to disconnecting all clients and cleaning up
remaining references. The problems arrise when using the IAsyncResult for
receiving data, once started a method is needed to successfully stop it at
*any* time.
I have looked back on past threads that I was involved in at the time
but still struggle to find the solution. As I understand it, I have to have
a public shared ManualResetEvent object for the client, as well as
implementing a state object to pass to the BeginRead method. But that is
about as much as I know, once I have a client connected to my server it
struggles to close correctly, as references are still "flying" about.
This is a brief outline of my current implementation...
Server)
* Contains a collection of client objects
1) A "start" method is called which contains a parameter for the
local port to listen on
2) A background thread is started which loops continuously calling
the "connect" method of a new client object and passing it the TCP listeners
AcceptTcpClient result.
3) Once a client connects its event handlers are initialized and it
is stored into the collection object. An event is then raised to notify the
main application that a client has just connected.
Client)
1) A "connect" method is called which contains an already initialized
TcpClient object which is to be passed by the server.
2) The TcpClients GetStream.BeginRead method is called and an
IAsyncResult object is created, this is stored in "module" level.
3) The TcpClients BeginRead async callback is raised when data is
recieved, if the data is 0 in length then the client is considered to be
disconnecting, otherwise an event is raised notifying the server of the
recieved data from the client and the BeginRead method is started again.
I have created a state object which contains 1 public property of
boolean type called "abortRequested" but I am unsure how to implement this.
If I create a public method called "close" for the client what should it
contain? Sorry for this long post but I am very eagre to get *a* method
working as I seem to be going around in circles! Thanks loads in advance!!!
Nick.
After recently coming across issues with implementing a UDP server for
interprocess communication; involving file transfer, I have decided to go
onto TCP.
Now I *have* created a TCP server in the past for VB.NET but had
troubles when it comes to disconnecting all clients and cleaning up
remaining references. The problems arrise when using the IAsyncResult for
receiving data, once started a method is needed to successfully stop it at
*any* time.
I have looked back on past threads that I was involved in at the time
but still struggle to find the solution. As I understand it, I have to have
a public shared ManualResetEvent object for the client, as well as
implementing a state object to pass to the BeginRead method. But that is
about as much as I know, once I have a client connected to my server it
struggles to close correctly, as references are still "flying" about.
This is a brief outline of my current implementation...
Server)
* Contains a collection of client objects
1) A "start" method is called which contains a parameter for the
local port to listen on
2) A background thread is started which loops continuously calling
the "connect" method of a new client object and passing it the TCP listeners
AcceptTcpClient result.
3) Once a client connects its event handlers are initialized and it
is stored into the collection object. An event is then raised to notify the
main application that a client has just connected.
Client)
1) A "connect" method is called which contains an already initialized
TcpClient object which is to be passed by the server.
2) The TcpClients GetStream.BeginRead method is called and an
IAsyncResult object is created, this is stored in "module" level.
3) The TcpClients BeginRead async callback is raised when data is
recieved, if the data is 0 in length then the client is considered to be
disconnecting, otherwise an event is raised notifying the server of the
recieved data from the client and the BeginRead method is started again.
I have created a state object which contains 1 public property of
boolean type called "abortRequested" but I am unsure how to implement this.
If I create a public method called "close" for the client what should it
contain? Sorry for this long post but I am very eagre to get *a* method
working as I seem to be going around in circles! Thanks loads in advance!!!
Nick.
