C# Examples - Unable to find
C# Examples - Unable to find
I have downloaded the Unity/.Net examples but am only finding Unity. I have started to do some C# web development and am looking for some examples specific to C#. Do any exist and can I be provided a link to them?
Re: C# Examples - Unable to find
Can you better explain what you mean with "c# web development"? If you are referring to ASP.Net for example, then your approach is wrong, because you can't make server pages communicate with SmartFoxServer.
If instead you are referring to Silverlight, then please read this post: http://forums.smartfoxserver.com/viewto ... ght#p52609
If instead you are referring to Silverlight, then please read this post: http://forums.smartfoxserver.com/viewto ... ght#p52609
Paolo Bax
The SmartFoxServer Team
The SmartFoxServer Team
Re: C# Examples - Unable to find
To be clearer, yes I am doing ASP.Net development with C# codebehind, having the server side libraries perform the communication with SFS & SQL Server Database. Once the SFS calls are completed I am firing events and sending the necessary data to the client for display/usage.
What I am doing is creating the Login & Zone selection via ASP.Net/C# before loading the gaming SWF.
The point that I am currently at; I have connected to SFS, and am working through some SFSEvent.LOGIN_ERROR issues with my extension.
Since it seems to be working so far I was looking for some clear examples of the C# inplementation but am only finding the Unity examples on your site.
Does my approach still not make any sense and should I change my direction on the client side?
If it now seems ok, Is there some C# specific examples?
Thanks
What I am doing is creating the Login & Zone selection via ASP.Net/C# before loading the gaming SWF.
The point that I am currently at; I have connected to SFS, and am working through some SFSEvent.LOGIN_ERROR issues with my extension.
Since it seems to be working so far I was looking for some clear examples of the C# inplementation but am only finding the Unity examples on your site.
Does my approach still not make any sense and should I change my direction on the client side?
If it now seems ok, Is there some C# specific examples?
Thanks
Re: C# Examples - Unable to find
To be honest this approach makes little sense. SmartFoxServer should be exposed directly to clients which should connect via socket. The way you are using it will make the overall performance and scalabilty very sloppy. This is because all clients will have to go through your HTTP server first, then to SFS, then back to the client via HTTP.
Take in consideration that HTTP is very slow and bloated compared to what SFS can do.
In this scenario you are throwing away all scalability, performance and protocol efficiency that SFS can deliver.
Take in consideration that HTTP is very slow and bloated compared to what SFS can do.
In this scenario you are throwing away all scalability, performance and protocol efficiency that SFS can deliver.
-
ThomasLund
- Posts: 1297
- Joined: 14 Mar 2008, 07:52
- Location: Sweden
Re: C# Examples - Unable to find
There should really be no major difference between using the API through ASP.net and through Unity. The main difference (and I'm sure somewhat confusing when looking at the Unity files) is that the Unity game engine provides some automagic callbacks into the code. E.g. Update() and FixedUpdate() and OnGUI().
Especially FixedUpdate in the examples provided are basically scheduled calls with a fixed interval.
So thats what you need to "emulate". Periodically emptying the response event queue - alternatively run the API in the non-threadsafe mode, where a response will immidiately perform a callback.
I've tried to hack together a small example from some code I have. I am not certain it compiles (sitting in a hotel with jetlag after 22 hours travel), but should give you the idea:
Especially FixedUpdate in the examples provided are basically scheduled calls with a fixed interval.
So thats what you need to "emulate". Periodically emptying the response event queue - alternatively run the API in the non-threadsafe mode, where a response will immidiately perform a callback.
I've tried to hack together a small example from some code I have. I am not certain it compiles (sitting in a hotel with jetlag after 22 hours travel), but should give you the idea:
Code: Select all
using System;
using System.IO;
using Sfs2X;
using Sfs2X.Core;
using Sfs2X.Entities;
using Sfs2X.Entities.Data;
using Sfs2X.Requests;
using Sfs2X.Logging;
namespace SFS2XConsoleTest
{
public class Sender
{
private string serverName = "127.0.0.1";
private int serverPort = 9933;
private SmartFox smartFox;
public void SendToServer ()
{
smartFox = new SmartFox (false);
// Register callback delegate
smartFox.AddEventListener (SFSEvent.CONNECTION, OnConnection);
smartFox.AddEventListener (SFSEvent.LOGIN, OnLogin);
smartFox.AddLogListener (LogLevel.ERROR, OnDebugMessage);
Console.WriteLine ("Connecting... ");
smartFox.ThreadSafeMode = false;
smartFox.Connect (serverName, serverPort);
}
public void OnConnection (BaseEvent evt)
{
bool success = (bool)evt.Params["success"];
string error = (string)evt.Params["error"];
Console.WriteLine ("On Connection callback got: " + success + " (error : <" + error + ">)");
if (success) {
Console.WriteLine ("Connected");
SmartFoxConnection.Connection = smartFox;
smartFox.Send (new LoginRequest ("", ""));
} else {
Console.WriteLine ("Connection failed");
}
}
public void OnLogin (BaseEvent evt)
{
try {
bool success = true;
if (evt.Params.ContainsKey ("success") && !(bool)evt.Params["success"]) {
Console.WriteLine ("Login error: " + (string)evt.Params["errorMessage"]);
} else {
Console.WriteLine ("Logged in successfully");
RoomSettings settings = new RoomSettings ("adminroom");
settings.GroupId = "game";
settings.IsGame = false;
settings.MaxUsers = 4;
settings.MaxSpectators = 0;
settings.Extension = new RoomExtension (ExtName, ExtClass);
smartFox.Send (new CreateRoomRequest (settings, true, smartFox.LastJoinedRoom));
}
} catch (Exception ex) {
Console.WriteLine ("Exception handling login request: " + ex.Message + " " + ex.StackTrace);
}
}
public void OnDebugMessage (BaseEvent evt)
{
string message = (string)evt.Params["message"];
Console.WriteLine ("[SFS DEBUG] " + message);
}
}
}
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
Follow on twitter: http://twitter.com/thomas_h_lund