Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Overriding events in WebSocket-Sharp client? #541

Open
kamilk91 opened this issue May 8, 2019 · 0 comments
Open

Overriding events in WebSocket-Sharp client? #541

kamilk91 opened this issue May 8, 2019 · 0 comments

Comments

@kamilk91
Copy link

kamilk91 commented May 8, 2019

Hi. My server is working fine with my

internal class ServerSocket : WebSocketBehavior

when i overrided methods like:

     protected override void OnMessage(MessageEventArgs e)
        {
            Send("Now, i starting to receeeive");
            var msg = e.Data;
            while (msg != "end")
            {
                Console.WriteLine("Send msg: \n");
                msg = Console.ReadLine();
                Send(msg);

            }

        }

        protected override void OnOpen()
        {
            Send("Hello conneted");
         
        }

        protected override void OnError(ErrorEventArgs e)
        {
            Console.WriteLine($"Eeerror {e.Message}");
            //Send(e.Message);
            //Console.WriteLine($"Error {e.Message} //send by server");
        }

        protected override void OnClose(CloseEventArgs e)
        {
            Send("Byeeeeeee //send by server");
        }

but when im using overriding methods in Client it cant handle any event

protected override void OnMessage(MessageEventArgs e)
        {
            Console.WriteLine(e.Data);
        }

        protected override void OnOpen()
        {

            JObject subscribe = new JObject();
            subscribe.Add("op", "subscribe");
            subscribe.Add("trades", "BTCUSD");
            subscribe.Add("args", "ALL");
            Send(subscribe.ToString());
        }

        protected override void OnError(ErrorEventArgs e)
        {
            Console.WriteLine($"Eeerror {e.Message}");

        }

        protected override void OnClose(CloseEventArgs e)
        {
            Send("unsubscribe");
        }


and i have to use it like in your example:

 soc.OnMessage += (sender, e) =>
            {
                Console.WriteLine(e.Data);
            };

            soc.OnOpen += (sender, e) =>
            {

            };

Why is it working like this? I dont think that im doing it wrong, because i did it exactly like with events in Server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant