Coder Social home page Coder Social logo

socket.io-unity-1's Introduction

socket.io-unity

on July. 7. 2020

Socket.IO Client Library for Unity (mono / .NET 4.x, Unity 2019.4.2.f1 LTS)

socket.io-unity by floatinghotpot is a very good project, but it had some problems with me. For example in the use of Action or Func. Exactly I could not use UniRx.

Installation

Download on release page socket.io-unity.unitypackage and import into Unity.

It's a C# file from a DLL inside a unity project.

Usage

unity player settings - other settings - configuration

  • Api Compatibility Level : .NET 4.x
// unity c# code
using Socket.Quobject.SocketIoClientDotNet.Client;
using UnityEngine;

public class TestObject : MonoBehaviour {
  private QSocket socket;

  void Start () {
    Debug.Log ("start");
    socket = IO.Socket ("http://localhost:3000");

    socket.On (QSocket.EVENT_CONNECT, () => {
      Debug.Log ("Connected");
      socket.Emit ("chat", "test");
    });

    socket.On ("chat", data => {
      Debug.Log ("data : " + data);
    });
  }

  private void OnDestroy () {
    socket.Disconnect ();
  }
}
// node js code
const app = require('express')();
const http = require('http').createServer(app);
const io = require('socket.io')(http);
app.get('/', (req, res) => {
    res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
  console.log('a user connected');
  socket.on('chat message', (msg) => {
    io.emit('chat message', msg);
  });
  socket.on('disconnect', () => {
    console.log('user disconnected');
  });
});
http.listen(3000, () => {
  console.log('Connected at 3000');
});

Features

This library supports all of the features the JS client does, including events, options and upgrading transport.

Framework Versions

  • Mono

  • .NET 4.x

    • Unity project setting - Scripting Runtime Version : .NET 4.x Equivalent
    • Unity project setting - Api Compatibility Level : .NET 4.x
    • Unity Editor restart

Demo

See floatinghotpot's demo document

Credit

Thanks to the authors of following projects:

socket.io-unity-1's People

Contributors

rocher0724 avatar

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.