UnitySocketIO
UnitySocketIO copied to clipboard
Error with Example code! Help!
Here is my code
using UnityEngine;
using SimpleJson;
using SuperSocket;
using WebSocket4Net;
using SocketIOClient;
public class test : MonoBehaviour{
// Use this for initialization
Client client = new Client("http://localhost:3998");
void Start () {
client.Opened += SocketOpened;
client.Connect();
}
void SocketOpened(object sender, MessageEventArgs e){
Debug.Log("connected");
}
// Update is called once per frame
void Update () {
}
}
This is my Error:
http://i.imgur.com/9NIwqhz.png
Same here :( sadly I got no solution for you so far.
I found a solution now. Only the SocketMessage event uses the MessageEventArgs class. All other events expect the normal EventArgs class. Change your code to that and make sure to import the System namespace (using System). That should fix this error.
i have same problem please help me
This id my code: using UnityEngine; using System.Collections; using System; using System.Collections.Concurrent; using System.Collections.Generic; using System.Diagnostics; //using System.Threading.Tasks; using System.Linq; using System.Net; using System.Threading; using SocketIOClient.Eventing; using SocketIOClient.Messages; using WebSocket4Net;
using SocketIOClient;
public class soketIO : MonoBehaviour {
SocketIOClient.Client client = new SocketIOClient.Client("http://localhost:80/");
// Use this for initialization
void Start () {
client.Opened += SocketOpened;
client.Message += SocketMessage;
client.SocketConnectionClosed += SocketConnectionClosed;
client.Error +=SocketError;
client.Connect();
}
private void SocketOpened(object sender, SocketIOClient.MessageEventArgs e) {
//invoke when socket opened
print ("soket is opened");
}
void Update(){
if(Input.GetKeyDown("c")){
//client.Send(SocketIOClient.Messages.IMessage);
}
}
private void SocketMessage (object sender, SocketIOClient.MessageEventArgs e) {
if ( e!= null && e.Message.Event == "message") {
string msg = e.Message.MessageText;
process(msg);
}
}
I got these errors :
Assets/soketIO.cs(25,24): error CS0123: A method or delegate soketIO.SocketOpened(object, SocketIOClient.MessageEventArgs)' parameters do not match delegate
System.EventHandler(object, System.EventArgs)' parameters
#########################################
Assets/soketIO.cs(25,24): error CS0428: Cannot convert method group SocketOpened' to non-delegate type
System.EventHandler'. Consider using parentheses to invoke the method
#########################################
Assets/soketIO.cs(27,50): error CS0103: The name SocketConnectionClosed' does not exist in the current context ######################################## Assets/soketIO.cs(28,32): error CS0103: The name
SocketError' does not exist in the current context
########################################
Assets/soketIO.cs(51,25): error CS0103: The name `process' does not exist in the current context
CapsE's Solution works for me.
private void SocketOpened(object sender, System.EventArgs e)
{
//invoke when socket opened
}
that all