[.Net] SmartFoxClient connection problem

Post here all your questions related with SmartFoxServer .Net/Unity3D API

Moderators: Lapo, Bax

DaveKinsella
Posts: 3
Joined: 15 Aug 2008, 08:27
Location: UK
Contact:

[.Net] SmartFoxClient connection problem

Postby DaveKinsella » 08 Sep 2008, 14:50

I'm having trouble getting the .net api client to connect to the smartfoxserver. The server is definitely running on the specified IP/port as I can connect the admin tool to it without a problem.

Abridged CodeBehind listing:

Code: Select all

using SmartFoxClientAPI;

public partial class _Default : System.Web.UI.Page
{
    public SmartFoxClient sfc;
    protected void Page_Load(object sender, EventArgs e)
    {
        SFSEvent.onDebugMessage += OnDebug;
        SFSEvent.onConnection += OnConnection;
        connectClient();
    }

    public void connectClient()
    {
        sfc = new SmartFoxClient(true);
        sfc.Connect(ConfigurationManager.AppSettings["sfs_ip"], int.Parse(ConfigurationManager.AppSettings["sfs_port"]));
    }

    public void OnConnection(bool success, string error)
    {
        if (success)
        {
            Trace.Write("SFS Connection", "Connection successful");
        }
        else
        {
            Trace.Write("SFS Connection", "Connection failed. Reason: " + error);
        }
    }

    public void OnDebug(string message)
    {
        Trace.Write("SFS Debug", message);
    }
}

Trace output excerpt:

Code: Select all

aspx.page    Begin Load
SFS Debug   Trying to connect
SFS Debug   [Sending]: <msg t='sys'><body action='verChk' r='0'><ver v='154' /></body></msg>
aspx.page    End Load
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 08 Sep 2008, 18:06

Hi!

I can try to help you. The reason I can only "try" is that I dont know the capabilities of ASP in terms of these kinds situations (I have never coded ASP).

So hop you can chime in, and we can solve this together.

What happens inside the SFS client is, that it sets up an async socket that waits for the reply to your command.

In other words it doesnt block your client code - async in its basic form.

So what I suspect happens is that your code finishes its execution before a result is received.

Try to put in an infinite while (1 == 1) loop or similar to keep the program running, and see if there is a response after a few milliseconds.
DaveKinsella
Posts: 3
Joined: 15 Aug 2008, 08:27
Location: UK
Contact:

Postby DaveKinsella » 09 Sep 2008, 07:36

Aha, I think you've hit the nail on the head there. I hadn't realised that the call was asynchronous. Hopefully I should be able to wait for the response and let the OnConnection handler break the loop.

Thanks for the help
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 09 Sep 2008, 18:04

I hope it works - please report back with your results!

:-)

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 8 guests