Comments (8)
use node.js socket.io-client emit the message include "-" , server can receive this message
from socket.io-client-unity3d.
@ppz0th @smallmiro
I tested again, not the symbol make this bug.
It's unknown bug!
c# login.cs
Socket.io server just can receive numberic string from socket.io-client-unity3d client.
I don't know why!!!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using socket.io;
public class Login : MonoBehaviour
{
Socket io;
// Use this for initialization
void Start ()
{
io = Socket.Connect ("http://localhost:7001/game");
io.On ("connect", () => {
print ("connect event");
io.Emit ("userJoin", "123456789");
io.Emit ("userJoin", "mdbj6");
io.Emit ("userJoin", "a1");
io.Emit ("userJoin", "1a");
io.Emit ("userJoin", "987654321");
io.Emit ("online", "123456789");
io.Emit ("online", "mdbj6");
io.Emit ("online", "a1");
io.Emit ("online", "1a");
io.Emit ("online", "987654321");
//server side console:
//userJoin token 123456789
//userJoin token 987654321
//online 123456789
//online 987654321
});
}
}
Node.JS socket.io client
In the Node.js socket.io-client all going well:
const io = require('socket.io-client');
const socket = io('http://127.0.0.1:7001/game');
socket.on('connect', () => {
console.log('connect!');
socket.emit('userJoin', '123456789');
socket.emit('userJoin', 'mdbj6');
socket.emit('userJoin', 'a1');
socket.emit('userJoin', '1a');
socket.emit('userJoin', '987654321');
socket.emit('online', '123456789');
socket.emit('online', 'mdbj6');
socket.emit('online', 'a1');
socket.emit('online', '1a');
socket.emit('online', '987654321');
});
//server side console:
//userJoin token 123456789
//userJoin token mdbj6
//userJoin token a1
//userJoin token 1a
//userJoin token 987654321
//online 123456789
//online mdbj6
//online a1
//online 1a
//online 987654321
server side
I use the egg.js framework and the egg.socket.io plugin, the egg.socket.io plugin is based on socket.io
exports.userJoin=function*(){
const msg = this.args[0];
console.log('userJoin',msg);
}
exports.online=function*(){
const msg = this.args[0];
console.log('online',msg);
}
from socket.io-client-unity3d.
@ppz0th @smallmiro
When the socket.io-client-unity3d client emit json format string , server can receive!
LoginData.cs
[Serializable]
public class LoginData
{
public string token;
public string Oh;
public string ToString ()
{
return JsonUtility.ToJson (this);
}
}
Login.cs
LoginData data = new LoginData ();
data.token = "1a2b3c";
data.Oh = "data";
io.On ("connect", () => {
print ("connect event");
io.Emit ("userJoin", data.ToString ());
io.Emit ("userJoin", "123456789");
io.Emit ("userJoin", "mdbj6");
io.Emit ("userJoin", "a1");
io.Emit ("userJoin", "1a");
io.Emit ("userJoin", "987654321");
io.Emit ("online", "123456789");
io.Emit ("online", "mdbj6");
io.Emit ("online", "a1");
io.Emit ("online", "1a");
io.Emit ("online", "987654321");
});
Where did other messages go?
from socket.io-client-unity3d.
@gzlock Thanks, I'll check this problem. Plz give me a hours..
from socket.io-client-unity3d.
@gzlock
Hello~
I've just check this issue and found a bug in packet-encoding. This issue will be fixed soon, Thanks~
Anyway the reason some packet is missing is an type casting failure in JavaSciprt.
In your code, a string only has numeric char is sent successfully because JavaScript can deduce it as an integer value. However other strings (ex "mdbj6", "a1", "1a"), JavaScript can't deduce it to an specific type.
So as an test, if you embrace all data with "", for example "mdb6" => "\"mdb6\"", you can successfully sent all messages.
from socket.io-client-unity3d.
@ppz0th
So now it will be automatically added ""bla bla bla"" ?
Hope it can!
from socket.io-client-unity3d.
Yeah. we're working on it~ Plz, wait for new release. Thanks :)
from socket.io-client-unity3d.
@gzlock
v1.1.1 has been just released. This issue is fixed. See send and receive messages sample and Check Emit() and EmitJson() method usage.
from socket.io-client-unity3d.
Related Issues (20)
- I just updated to 1.1.1, unity3d can't connect to socket.io server. HOT 6
- Support binary data HOT 2
- disconnect client HOT 2
- Implements Disconnect() method
- unity webSocketInstances is not defined,ReferenceError: webSocketInstances is not defined HOT 1
- Issue Solved when client get just eventName HOT 1
- run problem:JSON parse error HOT 2
- Not working with SSL server (https) HOT 4
- Parsing is not working properly. (And Disconnect issues) HOT 1
- Is not support HTTPS? HOT 4
- Event body wrong parsed HOT 1
- Download link in wiki is returnig 404 HOT 1
- Object reference not set to an instance of an object HOT 3
- Reconnect after an initial connection failure HOT 1
- Application.Quit() not work on iOS HOT 1
- SSL CertificateHandler in Socket for https connect HOT 4
- ArgumentException: JSON parse error: The document root must not follow by other values. HOT 2
- problem in reconnecting to socketio HOT 1
- No ability to pass EmitEvent, ListenEvent etc. as templates to Server.of(...) method
- Bad Request on localhost HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from socket.io-client-unity3d.