This project is read-only.

Send and Receive JSON with Websocket4NET on vb.net

Apr 28, 2016 at 3:42 AM
Hi there,

I am new with websocket/json and i have sample code to send and receive data from websocket with vb.net as per below

Public Class Form1
Private websocket As WebSocket4Net.WebSocket

Private Sub Button1_Click(sender As Object, ev As EventArgs) Handles Button1.Click
    websocket = New WebSocket4Net.WebSocket("wss://ws.sampleweb.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()
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)

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)

End Sub
End Class

And I want to receive the data and store in datagridview, is there anyone can help me with the code, thanks.

Regards,
Dhewa

attached is message received from above code..
Image