Using SmartFox with C# (III) : Frequently used functions

14 Sep

If you haven’t read below posts, you might wish to have a quick go through:

Using SmartFox with C# (I) : Installations and 1st handshaking
Using SmartFox with C# (II) : Login and join room

If you are comfortable with above implementations, you might be interested in below frequently called functions. Assuming below variable is instantiated successfully:

private SmartFox client;

To Send a message:

client.Send(new PublicMessageRequest(someMessage));
client.AddEventListener(SFSEvent.PUBLIC_MESSAGE, OnPublicMessage);
private void OnPublicMessage(BaseEvent evt) {
     User sender = (User) evt.Params[“sender”];
     string message = (string) evt.Params[“message”];   

To create a room:

var settings = new RoomSettings(“New Room Name”);
settings.maxUsers = 100;
Settings.groupId = “ChatGroup”;
client.Send(new CreateRoomRequest(settings));
client.addEventListener(SFSEvent.ROOM_ADD, OnRoomAdded);

For a zone, to join/remove a room:

client.Send(new Sfs2X.Requests.JoinRoomRequest(roomId));
client.AddEventListener(SFSEvent.ROOM_JOIN, OnRoomJoin);
private void OnRoomJoin(BaseEvent evt) {
     Room room = (Room) evt.Params[“room”];           
     //room.Name,  room.UserList

For user to enter/leave a room

client.Send(new Sfs2X.Requests.LeaveRoomRequest());
client.AddEventListener(SFSEvent.USER_EXIT_ROOM, OnUserExitRoom);
private void OnUserExitRoom(BaseEvent evt) { User user = (User) evt.Params[“user”]; }

For more information, have a read on SFSEvent class and Sfs2X.Requests namespace will be vey helpful.


Posted by on September 14, 2015 in Dotnet/C#, Programming, Unity 3d


Tags: , , , , ,

2 responses to “Using SmartFox with C# (III) : Frequently used functions

  1. Oscar

    September 4, 2016 at 3:58 pm

    But how to code at the backend damn server!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: