B4J Question Multi client TCP using JNetwork

nosaj66au

Member
Licensed User
Longtime User
Hi All,
Looking for some advice. I have created a small application to push a "text" string to multiple client over multiply TCP connections. All clients will receive the same string at a time interval therefore very little client management is required (no client requests). I have been using a array of sockets and astreams and as a new connection comes in it attaches to the next available socket and astream. Originally I captured what sockets/astreams were being used and only wrote (astream.write) to the connected astream outputstream. As I refined the code I accidentally wrote to all astream outputsstreams in the array regardless of connection state. To my surprise it worked and didn't throw an error. If this is a valid use and if doesn't cause memory leaks or stack problem it can reduce the client management code by heaps.

In short :
Can using astream.Write to an unconnected astream object without causing an issue or problem?

Jason
 
Last edited:

Erel

B4X founder
Staff member
Licensed User
Longtime User
Upvote 0

nosaj66au

Member
Licensed User
Longtime User
Thanks Erel
I have added the Terminated and error events. However as my AsyscStreams are in an array and I would like to use a common event name. Is there anyway to determine which AsysStream generated the event without creating a new class to do it?

event deceleration something like:- "Sub Astream_error(index as int) " where index it the element ?

Jason
 
Upvote 0

nosaj66au

Member
Licensed User
Longtime User
Next time I should look before hitting the keyboard. :)

".IndexOf(Sender)" right?

To use "Sender" must it be a list or will an array work?

Jason
 
Upvote 0
Top