Vbnet handshake problem

Hello, i'm developing vb.net application, i have a problem even if the command connect give me result ok, when i send data i got always you must send data only if websocket is open...
Could you help me:?

Private websocket As WebSocket4Net.WebSocket
Sub Main()

WebSocket = New WebSocket4Net.WebSocket("wss://ws.binaryws.com/websockets/v3")
AddHandler WebSocket.Opened, Sub(s, e) socketOpened(s, e)
AddHandler WebSocket.Error, Sub(s, e) socketError(s, e)
AddHandler WebSocket.Closed, Sub(s, e) socketClosed(s, e)
AddHandler WebSocket.MessageReceived, Sub(s, e) socketMessage(s, e)
AddHandler WebSocket.DataReceived, Sub(s, e) socketDataReceived(s, e)

websocket.Open()
Console.WriteLine(websocket.State)

websocket.Send("{""ticks_history"":""R_50"",""end"":""latest"",""count"":10}")

End Sub

Sub socketClosed(s As Object, e As EventArgs)

End Sub

Sub socketError(s As Object, e As SuperSocket.ClientEngine.ErrorEventArgs)
MsgBox(e.Exception.ToString
)
End Sub

Sub socketMessage(s As Object, e As WebSocket4Net.MessageReceivedEventArgs)
MsgBox(e.Message)
End Sub

Sub socketDataReceived(ss As Object, e As WebSocket4Net.DataReceivedEventArgs)
MsgBox(e.Data)
End Sub

Comments

  • edited September 27

    Hello,
    i update my code but the result it's the same... the socket will not open...

    Imports WebSocket4Net
    Imports System.Text
    
    
    Imports System.Threading
    
    Module Module1
        Private websocket As WebSocket4Net.WebSocket
        Sub Main()
            websocket = New WebSocket4Net.WebSocket("wss://ws.binaryws.com/websockets/v3?app_id=10789")
            AddHandler WebSocket.Opened, Sub(s, e) socketOpened(s, e)
            AddHandler WebSocket.Error, Sub(s, e) socketError(s, e)
            AddHandler WebSocket.Closed, Sub(s, e) socketClosed(s, e)
            AddHandler WebSocket.MessageReceived, Sub(s, e) socketMessage(s, e)
            AddHandler WebSocket.DataReceived, Sub(s, e) socketDataReceived(s, e)
    
            websocket.Open()
            Console.WriteLine(websocket.State)
        End Sub
    
        Sub socketOpened(s As Object, e As EventArgs)
            websocket.Send("{""ticks_history"":""R_50"",""end"":""latest"",""count"":10}")
        End Sub
    
        Sub socketClosed(s As Object, e As EventArgs)
    
        End Sub
    
        Sub socketError(s As Object, e As SuperSocket.ClientEngine.ErrorEventArgs)
            MsgBox(e.Exception.ToString
                   )
        End Sub
    
        Sub socketMessage(s As Object, e As WebSocket4Net.MessageReceivedEventArgs)
            MsgBox(e.Message)
        End Sub
    
    
        Sub socketDataReceived(ss As Object, e As WebSocket4Net.DataReceivedEventArgs)
            MsgBox(e.Data)
        End Sub
    
    End Module
    
  •     private void MetroMain_Load(object sender, EventArgs e)
        {
    
            ws = WebSocketWrapper.Create("wss://ws.binaryws.com/websockets/v3?app_id=1089");
            ws.Connect();
            ws.OnMessage(OnMessage);
            ws.OnDisconnect(OnDisconnect);
            ws.OnConnect(OnConnect);
    
            _timer.Interval = (1 * 60 * 1000); 
            _timer.Tick += _timer_Tick;
            _timer.Start();
    
            _pingTimer.Interval = 10 * 1000;
            _pingTimer.Tick += _pingTimer_Tick;
            _pingTimer.Start();
        }
    
        private void _pingTimer_Tick(object sender, EventArgs e)
        {
            metroLabelWins.InvokeIfRequired(c =>
            {
                c.Text = "Win: " + _proposals.Count(x => x.Key.amount.HasValue && x.Key.amount.Value > 0);
            });
    
            metroLabelLosses.InvokeIfRequired(c =>
            {
                c.Text = "Loss: " + _proposals.Count(x => x.Key.amount.HasValue && x.Key.amount.Value == 0);
            });
    
            SendMessage(JsonConvert.SerializeObject(new { ping = "1" }));
        }
    
        private void _timer_Tick(object sender, EventArgs e)
        {
            foreach(var proposal in _proposals)
            {
                if (!proposal.Value.amount.HasValue)
                {
                    var checkTrade = new
                    {
                        proposal_open_contract = 1,
                        contract_id = proposal.Value.contract_id
                    };
                    SendMessage(JsonConvert.SerializeObject(checkTrade));
                }
            }
        }
    
  • @Raunak Would appreciate if you could assist to check for this query, Thank you

  • thanks Brian, but my problem is after connect command... the socket will not open..

  • As per the screenshot, you are sending ping just after websocket.open that will not work as websocket is not opened yet. need to move that ping in socketMessage

  • I get it. When you call Websocket.Open it asks the websocket to open, but doesn't wait for the socket to open. That is why the ping request fails.

Sign In or Register to comment.