Giter VIP home page Giter VIP logo

Comments (8)

gzlock avatar gzlock commented on June 5, 2024

use node.js socket.io-client emit the message include "-" , server can receive this message

from socket.io-client-unity3d.

gzlock avatar gzlock commented on June 5, 2024

@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.

gzlock avatar gzlock commented on June 5, 2024

@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");
});

server console:
image

Where did other messages go?

image

from socket.io-client-unity3d.

smallmiro avatar smallmiro commented on June 5, 2024

@gzlock Thanks, I'll check this problem. Plz give me a hours..

from socket.io-client-unity3d.

ppz0th avatar ppz0th commented on June 5, 2024

@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.

gzlock avatar gzlock commented on June 5, 2024

@ppz0th
So now it will be automatically added ""bla bla bla"" ?
Hope it can!

from socket.io-client-unity3d.

ppz0th avatar ppz0th commented on June 5, 2024

Yeah. we're working on it~ Plz, wait for new release. Thanks :)

from socket.io-client-unity3d.

ppz0th avatar ppz0th commented on June 5, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.