B4J Question Multi client TCP using JNetwork

Discussion in 'B4J Questions' started by nosaj66au, Jul 23, 2015.

  1. nosaj66au

    nosaj66au Member Licensed 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?

    Last edited: Jul 23, 2015
  2. Erel

    Erel Administrator Staff Member Licensed User


    Though you should handle the terminated and error events and remove disconnected AsyncStreams.

    Make sure to check this solution: Custom WebSocket Based Push Framework

    It will most probably work better.
    lemonisdead likes this.
  3. nosaj66au

    nosaj66au Member Licensed 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 ?

  4. nosaj66au

    nosaj66au Member Licensed 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?

  5. Erel

    Erel Administrator Staff Member Licensed User

    You can just write: Dim astream As AsyncStream = Sender
    lemonisdead likes this.