Login  
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: Syntax for SERVER to send messages to all connected clients
TMS

From: Kula, USA
Posts: 6
Member Since: 02/01/11
posted February 1, 2011 3:43 PM

Hi,


In a Winforms app containing a SERVER component, I would like to send a message to all the connected clients.

I start the server with

  server1.Listen(socketnum);

At this point, clients can connect, and I see them with

  server1.Connections.Count

Intuitively, I would think something like this would be the C# syntax:

  for (int i=0;i<server1.Connections.Count;i++){
    server1.Connection[i].Send("Hello"+\r\n);
  }

The above methods do not exist.

Can somebody please suggest the proper way to accomplish this.


Thanks
Nick B (Admin)

From: Utica, NY USA
Posts: 583
Member Since: 05/25/10

Extra Support Options
Custom Application Development

posted February 1, 2011 4:09 PM

Hello,

Are you looking for the Write method? In the 4.x redesign, we changed our methods to be more in line with the Streams interface.
TMS

From: Kula, USA
Posts: 6
Member Since: 02/01/11
posted February 1, 2011 4:36 PM

Yes, I am looking for the proper syntax to invoke the Write or WriteTo method (writing from a server to all attached clients).

Although I recently bought a subscription to .Net PowerTCP Sockets 4.3, I am maintaining this application from an older PowerTCP version (purchased March of '10) so the Streams modification you mention may not apply.

Can you point me to an example of implementing this?
Nick B (Admin)

From: Utica, NY USA
Posts: 583
Member Since: 05/25/10

Extra Support Options
Custom Application Development

posted February 1, 2011 4:56 PM

Hello,

I meant that there is a Write() method, not a Send() method in our 4.x product, I'm sorry for the confusion.

The sample you provide should perform what you are referring to, but I noticed that you are referencing server1.Connection[i], not server1.Connections[i]

There is a similar example in the help documentation for the Connections property, copied here:

// Echo data back to all clients
foreach(Tcp tcp in server1.Connections)
{
   // Preface text with user name (from Tcp.Tag) and send
   tcp.Stream.Write(e.Tcp.Tag.ToString() + ": " + text + "\r\n");
}
TMS

From: Kula, USA
Posts: 6
Member Since: 02/01/11
posted February 1, 2011 5:23 PM

Thanks, exactly what I was looking for.
Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX