You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
41 lines
1.3 KiB
41 lines
1.3 KiB
2 years ago
|
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
|
||
|
using WebSocketServer;
|
||
|
|
||
|
public class MyWebSocketServer : WebSocketServer.WebSocketServer
|
||
|
{
|
||
|
override public void OnOpen(WebSocketConnection connection) {
|
||
|
// Here, (string)connection.id gives you a unique ID to identify the client.
|
||
|
Debug.Log(connection.id);
|
||
|
}
|
||
|
|
||
|
override public void OnMessage(WebSocketMessage message) {
|
||
|
// (WebSocketConnection)message.connection gives you the connection that send the message.
|
||
|
// (string)message.id gives you a unique ID for the message.
|
||
|
// (string)message.data gives you the message content.
|
||
|
Debug.Log(message.connection.id);
|
||
|
Debug.Log(message.id);
|
||
|
Debug.Log(message.data);
|
||
|
}
|
||
|
|
||
|
|
||
|
override public void OnClose(WebSocketConnection connection) {
|
||
|
// Here is the same as OnOpen
|
||
|
Debug.Log(connection.id);
|
||
|
}
|
||
|
|
||
|
public void onConnectionOpened (WebSocketConnection connection) {
|
||
|
Debug.Log("Connection opened: " + connection.id);
|
||
|
}
|
||
|
|
||
|
public void onMessageReceived (WebSocketMessage message) {
|
||
|
Debug.Log("Received new message: " + message.data);
|
||
|
}
|
||
|
|
||
|
public void onConnectionClosed (WebSocketConnection connection) {
|
||
|
Debug.Log("Connection closed: " + connection.id);
|
||
|
}
|
||
|
}
|