UnitySocketIO icon indicating copy to clipboard operation
UnitySocketIO copied to clipboard

Error with Example code! Help!

Open ghost opened this issue 11 years ago • 5 comments

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

ghost avatar Feb 11 '14 07:02 ghost

Same here :( sadly I got no solution for you so far.

CapsE avatar Apr 25 '14 15:04 CapsE

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.

CapsE avatar Apr 30 '14 09:04 CapsE

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 delegateSystem.EventHandler(object, System.EventArgs)' parameters ######################################### Assets/soketIO.cs(25,24): error CS0428: Cannot convert method group SocketOpened' to non-delegate typeSystem.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 nameSocketError' does not exist in the current context ######################################## Assets/soketIO.cs(51,25): error CS0103: The name `process' does not exist in the current context

saied63 avatar Sep 17 '14 07:09 saied63

CapsE's Solution works for me.

CSEliot avatar Mar 09 '15 04:03 CSEliot

private void SocketOpened(object sender, System.EventArgs e)
{
    //invoke when socket opened
}

that all

withtea avatar Jun 09 '15 14:06 withtea