Question: I've been trying to solve this simple problem, but I cannot make it work.
I am using `WebSocketSharp.Server`. The code can be seen below.

In my `NetworkClass` I have `someData` I would like to send to the client when a message is received. The problem is the `OnMessage` event gets fired in a different class, and I don't know how the access the instance of this class.

Broadcasting to all clients form the `NetworkClass` works fine and receiving messages form the client works fine as well.

```cs
public class IndexRoute : WebSocketBehavior {

    protected override void OnMessage(MessageEventArgs e) {
       Console.WriteLine("Received message form client: "+e.Data);

       //TODO: send someData string to client

    }

}

public class NetworkClass {

    String someData = "TestData";
    WebSocketServer server = new WebSocketServer("ws://127.0.0.1:5000");

    public NetworkClass() {

        server.AddWebSocketService<IndexRoute>("/");
        server.Start();

        Console.WriteLine("Server started");
    }

    public void broadcastData() {

        server.WebSocketServices["/"].Sessions.Broadcast(someData);
        Console.WriteLine("Broadcast");

    }

}

```

Answer: 
I combined the answers of Jeroen van Langen and Jesper. The key was to pass the instance of the `NetworkClass` to the `IndexRoute` class and access the variables from there.

`server.AddWebSocketService<IndexRoute>("/", () => new IndexRoute(this));`
works but is marked as obsolete.

```
public class IndexRoute : WebSocketBehavior {

    private NetworkClass _instanceOfNetworkClass;

    public IndexRoute(NetworkClass instanceOfNetworkClass)
    {
        _instanceOfNetworkClass = instanceOfNetworkClass;
    }

    protected override void OnMessage(MessageEventArgs e) {
       Console.WriteLine("Received message form client: "+e.Data);

       //Broadcast someData string to clients
       Sessions.Broadcast(_instanceOfNetworkClass.someData);
    }

}

public class NetworkClass {

    public String someData = "TestData";
    WebSocketServer server = new WebSocketServer("ws://127.0.0.1:5000");

    public NetworkClass() {

        server.AddWebSocketService<IndexRoute>("/", () => new IndexRoute(this));
        server.Start();

        Console.WriteLine("Server started");
    }

    public void broadcastData() {

        server.WebSocketServices["/"].Sessions.Broadcast(someData);
        Console.WriteLine("Broadcast");

    }

}

```
When you inherit `WebSocketBehavior`, you get methods and properties that allow you to find out information about the connection you are currently talking to. In this case, just use one of the `Send` methods to send to the connection that sent the message:

```cs
protected override void OnMessage(MessageEventArgs e) {
    Console.WriteLine("Received message form client: "+e.Data);
    Send(/* pick one of the overloads to suit your needs */);
}

```

You can also use the property `Context` to get a `WebSocketContext` with information about the connection, or `ID` to find the session (connection) ID, which you could pass to another object. If the question is how you find your instance of NetworkClass, you are already constructing the IndexRoute yourself, just pass `this` in as an additional parameter.