Сообщение от moka
Прикольно.
Как понимаю нужен обмен Policy чтобы сделать нормальное общение? (также как в flash'е?).
|
Да, WebPlayer Unity так же проверяет возможность подключения как и флеш.
Сообщение от moka
packetProcesors - как понимаю ты пушаешь функцию потом которая будет вызываться для каждого пакета.
|
Да там похоже на middleware в express
Сообщение от moka
Как тебе подход как в socket.io? В плане имён пакетов и подпиской на них?
|
Вчера написал по просьбе ant2on'а нечто похожее на socket.io как враппер над своим сервером.
Node js
var util = require('util');
var NodeSharpTCP = require('NodeSharpTCP');
// полиси сервер
var SocketPolicyServer = NodeSharpTCP.SocketPolicyServer;
SocketPolicyServer.listen(__dirname + '/public/crossdomain.xml', 843);
// евент сервер
var EventServer = NodeSharpTCP.EventServer;
var server = new EventServer();
server.on('connection', function(client){
console.log('Clients: '+ server.clients.length);
client.emit('welcome', {id: client.id});
client.on('disconnect', function(){
console.log('Clients: '+ server.clients.length);
});
client.on('message', function(msg){
console.log('message: '+ util.inspect(msg));
client.sendMessage(msg);
});
client.on('custom-event', function(data){
console.log('custom-event: '+ util.inspect(data));
client.emit('custom-event', data);
});
});
server.listen(8124, function(){
console.log('Event Server bound')
});
Unity/C#
using System.Collections.Generic;
using BinarySerialization;
using UnityEngine;
using System.Collections;
public class EventServerClientTest : MonoBehaviour
{
private EventServerClient _client;
public void Start ()
{
_client = GetComponent<EventServerClient>();
_client.On("connect", OnConnect);
_client.On("welcome", OnWelcome);
_client.On("custom-event", OnCustomEvent);
_client.Connect();
}
private void OnCustomEvent(object obj)
{
Debug.Log("Custom Event Received: " + obj.ToDebugString());
}
private void OnWelcome(object obj)
{
var welcomeEvent = (Dictionary<string, object>) obj;
Debug.Log("Welcome: " + welcomeEvent["id"]);
}
private void OnConnect(object obj)
{
Debug.Log("OnConnect");
_client.Emit("custom-event", new object[]{1, true, "three"});
}
}