EldoS | Feel safer!

Software components for data protection, secure storage and transfer

Can WebSocket be Event-based?

Also by EldoS: CallbackDisk
Create virtual disks backed by memory or custom location, expose disk images as disks and more.
#33571
Posted: 06/05/2015 04:58:17
by Fanglin Liu (Priority Standard support level)
Joined: 05/14/2015
Posts: 33

Look at the following code. The WebSocket is polling based. Can we change it to event-based.

Code
   public class WSThread
    {
        TElWebSocketClient m_WSClient;
        TElSocket m_Socket;

        public WSThread(TElWebSocketClient WSClient, TElSocket Socket)
        {
            m_WSClient = WSClient;
            m_Socket = Socket;
        }

        public void Execute()
        {
            while (m_Socket.State == SBSocket.Unit.issConnected)
            {
                try
                {
                    if (m_Socket.CanReceive(500))
                        m_WSClient.DataAvailable();
                    else
                        Thread.Sleep(50);
                }
                catch (Exception)
                {
                    break;
                }
            }

            try
            {
                m_WSClient.Close(false);

                while (m_WSClient.Active && (m_Socket.State == SBSocket.Unit.issConnected))
                    m_WSClient.DataAvailable();

                m_Socket.Close(false);
            }
            catch (Exception)
            {
                ;
            }
        }
    }
#33572
Posted: 06/05/2015 05:05:49
by Vsevolod Ievgiienko (EldoS Corp.)

Thank you for contacting us.

TElWebSocketClient is event based. Please check documentation for details: https://www.eldos.com/documentation/sb...lient.html

TElWebSocketClient itself doesn't work with network layer - its just a data parser. Above code is needed to feed the instance with incoming data and events will be fired during data processing.
#33594
Posted: 06/07/2015 21:22:29
by Fanglin Liu (Priority Standard support level)
Joined: 05/14/2015
Posts: 33

Thanks.

Reply

Statistics

Topic viewed 531 times

Number of guests: 1, registered members: 0, in total hidden: 0




|

Back to top

As of July 15, 2016 EldoS Corporation will operate as a division of /n software inc. For more information, please read the announcement.

Got it!