Search All Forums
Dart Home | PowerTCP Sockets for .NET | Custom Development Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
AuthorForum: PowerTCP Sockets for .NET (Secure and Standard)
Topic: Open a connection as host

From: Kaysville, UT USA
Posts: 3
Member Since: 11/26/10
posted May 20, 2014 2:32 PM

I have a server application that runs Dart Sockets version It runs a thread for each client that sends a message.
To start the server it runs this code:
 Friend WithEvents Host As Dart.Sockets.Server
 Host.Start(AddressOf Host_NewConnection, New System.Net.IPEndPoint(ip, cd.ListenPort), m_SelectedProtocol)

After that is run when it receives a message the Host_NewConnection Sub Procedure is run and the message is handled.

My question is: instead of waiting for the client to send me a message I want to establish a connection with the client, leave it open, and then wait for messages to come in from the client.

How can I do this?
Jason Farrar (Admin)

From: USA
Posts: 223
Member Since: 07/24/07

Extra Support Options
Custom Application Development

posted May 29, 2015 12:28 PM

If you just want to persist the connection you can call Tcp.ReadAsync instead of Tcp.Read in your Host_NewConnection sub procedure.

Tcp.ReadAsync requires an async callback which will be executed when the receive completes, you would put your message handling logic in this callback instead of in Host_NewConnection. After your message handling code, you would call Tcp.ReadAsync again and pass in the same async call back. Reference the first VB example in the following link for more information:

If you want to establish outgoing connections then you wouldn't use the server component. You would use a collection of TCP components and add to it as each connection to a client is established. In this scenario, the client is essentially acting as the server so you would need to call Tcp.Socket.Accept on the client-side in order for it to accept connections from the server. You would probably still want to use Tcp.ReceiveAsync on the server side though. I wouldn't really recommended doing this though, it will get complicated fairly quickly.
Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX