NetEase / UnitySocketIO

socket.io client for unity3d.
888 stars 229 forks source link

Error with Example code! Help! #21

Open ghost opened 10 years ago

ghost commented 10 years ago

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

CapsE commented 10 years ago

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

CapsE commented 10 years ago

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.

saied63 commented 10 years ago

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

CSEliot commented 9 years ago

CapsE's Solution works for me.

withtea commented 9 years ago
private void SocketOpened(object sender, System.EventArgs e)
{
    //invoke when socket opened
}

that all