简体   繁体   中英

Can't connect to MtGox Websocket

I've tried every possibily combination for the URI, below is my code. When using the webpage http://www.websocket.org/echo.html and for "Location: " entering ws://websocket.mtgox.com/mtgox, the webpage shows a nice feed for the stream. But when I copy and paste their example below, and use the same URI for the stream, I get "Error: Undefined" and the "DISCONNECTING". I've tried converting this to VB, as per the example below, with no luck. Any ideas as to what I am doing wrong?

Imports WebSocket4Net

Module Module1

Sub Main()

    Dim websocket As New WebSocket4Net.WebSocket("ws://websocket.mtgox.com:80/mtgox")
    Dim stream As String

    Console.WriteLine(websocket.State)
    Console.ReadKey()




    AddHandler websocket.Opened, Sub(s, e) socketOpened()
    AddHandler websocket.Error, Sub(s, e) socketError()
    AddHandler websocket.Closed, Sub(s, e) socketClosed()
    AddHandler websocket.MessageReceived, Sub(s, e) socketMessage()
    AddHandler websocket.DataReceived, Sub(s, e) socketDataReceived()

    websocket.Open()

    Console.ReadKey()

End Sub

Sub socketOpened()
    MsgBox("Opened")
End Sub

Sub socketClosed()
    MsgBox("Closed")
End Sub

Sub socketError()
    MsgBox("Error")
End Sub

Sub socketMessage()
    'MsgBox(e)
End Sub

Sub socketDataReceived()
    MsgBox("Data received")
End Sub

End Module

I am not familiar with WebSocket4Net, but this may be related to a similar issue that someone had with another library ( MtGox API and websocketpp ) where the lack of an Origin header caused MtGox to cancel the connection with a 403 error.

It worked from browsers because they all send the Origin header. If your WebSocket implementation has a method of adding an Origin header to the outgoing handshake that might be worth a shot.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM