Created
August 18, 2012 02:54
-
-
Save prabirshrestha/3384062 to your computer and use it in GitHub Desktop.
socket-io-net-sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var io = new SocketIo(); | |
io.Sockets.On("connection", socket => { | |
io.Sockets.Emit("this", new { will = "be received by everyone "}); | |
socket.On("private message", (from, msg) => { | |
Debug.WriteLine("I received a private message by " + from + " saying " + msg); | |
}); | |
socket.On("disconnect", () => { | |
io.Sockets.Emit("user disconnected"); | |
}); | |
}); | |
RouteTable.Routes.Add(new Route("*", new SimpleOwinAspNetRouteHandler(io.App))); | |
public class SocketIo { | |
public Sockets Sockets { get; } | |
public Sockets Of(string path); | |
public AppFunc App(); | |
} | |
public interface ISocketIoEventEmitter { | |
public void Emit(string eventName, object message); | |
public void Emit(string eventName); | |
public void On(string eventName, Action callback); | |
public void On(string eventName, Func<Task> callback); | |
public void On(string eventName, Action<dynamic /* message */> callback); | |
public void On(string eventName, Func<dynamic /* message */, Task> callback); | |
public void On(string eventName, Action<string /* from */, dynamic /* message*/> callback); | |
public void On(string eventName, Func<string /* from */, dynamic /* message*/, Task> callback); | |
} | |
public interface ISocketIoStore { | |
public Task Set(string name, object obj); | |
public Task<object> Get(string name); | |
public Task<T> Get(string name); | |
} | |
public class SocketIoSockets : ISocketIoEventEmitter { | |
public ISocketIo Broadcast { get; } | |
} | |
public class SocketIoSocket : ISocketIoEventEmitter, ISocketIoStore { | |
public Socket Volatile { get; } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment