nhn / socket.io-client-unity3d

socket.io-Client for Unity3D, which is compatible with socket.io v1.x
Other
167 stars 42 forks source link

Fixes JSON parse error #20

Closed iBicha closed 6 years ago

iBicha commented 7 years ago

Fixes ArgumentException: JSON parse error: The document root must not follow by other values.

While the code checks for string starting with "{", it didnt check for ending with "}".

ppz0th commented 7 years ago

@iBicha Hello~ The modified code will be merged soon. Thanks~ :) But I wonder in which case ArgumentException occurs. Could you dump and show your answer packet? Because the answer packet made by socket.io server code and it can't be make any json parsing error.

iBicha commented 7 years ago

I can provide a dump tomorrow, but i remember well the packet started and ended with a number, with the json payload in between.

ppz0th commented 7 years ago

@iBicha Hmm.. Can you tell me which version of socket.io-server installed? We're only supporting socket.io upto v1.7.4 and not v2.

iBicha commented 7 years ago

@ppz0th Oh I see now! it's a "socket.io": "^2.0.1" in the package.json so that might be it. On a side note, this got it working, so why not consider a v2 compatibility since it's easy to support?

ppz0th commented 7 years ago

@iBicha Really??;;;; Last time i tested it didn't work at all. I will check on socket.io V2 right now :)

iBicha commented 7 years ago

Yes, after this change, I was able to get a simple chat going between Unity and the browser with a v2 server running. Here's a dump of the response that this PR fixes:

97:0{"sid":"zrd2ZurkTf49oFrVAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":60000}2:40 As you can see there is some padding to the JSON. According to the engine.io protocol, 97 is probably the size, and 0 should be to indicate type open

What is weird is the appended meta data, where 2 should indicate a ping message, but it's weird to have it at the end of the packet

iBicha commented 7 years ago

@ppz0th where you able to run it?