socket.io-client-unity3d icon indicating copy to clipboard operation
socket.io-client-unity3d copied to clipboard

Issue Solved when client get just eventName

Open huseong opened this issue 8 years ago • 1 comments

When I emit event that is consist of just event name in my node server socket.emit('version') Than issue occurs in client because of the parsing problem. When I check the event using Debug.log() It looks like ["version"] . So I change Socket.cs code. before

                    var seperateIndex = pkt.body.IndexOf(", ");

                    var seperatorLen = 2;
                    if (seperateIndex == -1) {
                        seperateIndex = pkt.body.IndexOf(',');
                        seperatorLen = 1;
                    }

                    var eventName = pkt.body.Substring(2, seperateIndex - 3);
                    if (!_handlers.ContainsKey(eventName)) {
                        Debug.LogWarningFormat("{0} event doesn't have a handler", eventName);
                        break;
                    }

after

                    int seperateIndex = pkt.body.IndexOf(", ");
                    int seperatorLen = 2;
                    if (seperateIndex == -1) {
                        seperateIndex = pkt.body.IndexOf(',');
                        if (seperateIndex == -1) {
                            seperateIndex = pkt.body.Length - 1;
                        }
                        seperatorLen = 1;
                    }
                    string eventName = pkt.body.Substring(2, seperateIndex - 3);
                    if (!_handlers.ContainsKey(eventName)) {
                        Debug.LogWarningFormat("{0} event doesn't have a handler", eventName);
                        break;
                    }
                    if (eventName.Length == pkt.body.Length - 4) {
                        _handlers[eventName]("");
                        break;
                    }

huseong avatar Nov 20 '17 09:11 huseong

@huseong Sorry for my late reply on your issue. Thanks to your report~ I'll check this and apply on develop branch. Or you can make Pull-Request to develop branch. This make me easy to apply your change on our code.

ppz0th avatar Dec 07 '17 02:12 ppz0th