Use Mono Api with monotouch.

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

Moderators: Lapo, Bax

User avatar
kotbegemot
Posts: 82
Joined: 21 Nov 2010, 05:05
Location: Saint-Petersburg

Use Mono Api with monotouch.

Postby kotbegemot » 24 Nov 2011, 09:09

Can i use Mono Api with Mono Touch ?
I try to use it in mono touch, but onConnection Handler not start.
BUT THEN I CLOSE APP, server log write: remove socket channel it means its connected but onConnection not started. PLEASE HELP



MY LOG HERE:

log: [ RECEIVED ]: <cross-domain-policy><allow-access-from domain='*' to-ports='9339' /></cross-domain-policy>, (len: 91)
log: [ RECEIVED ]: <msg t='sys'><body action='apiOK' r='0'></body></msg>, (len: 53)
log: Disconnect due to lost socket connection
log: Disconnect Exception: System.Net.Sockets.SocketException: The socket is not connected
at System.Net.Sockets.Socket.Shutdown (SocketShutdown how) [0x00058] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net.Sockets/Socket_2_1.cs:1432
at SmartFoxClientAPI.SmartFoxClient.Disconnect () [0x00000] in <filename unknown>:0
Trying to call onConnectionLost, but no callback is registered
Terminating in response to SpringBoard's termination.



MY CODE HERE:



[code]using MonoTouch.UIKit;
using System.Drawing;
using System;
using MonoTouch.Foundation;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Handlers;

namespace PokerIosMobile1_2
{
public partial class HomeViewController : UIViewController
{
SelectLoginView selectLoginView; //Окно выбора типа входа - 2


//----------------------------------------------------------
// SmartFox Setup variables
//----------------------------------------------------------
private string ip = "192.168.105.193";
private int port = 9339;
//private string statusMessage = "";

static bool UserInterfaceIdiomIsPhone {
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}

public HomeViewController ()
: base (UserInterfaceIdiomIsPhone ? "HomeViewController_iPhone" : "HomeViewController_iPad", null)
{
}

public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();

// Release any cached data, images, etc that aren't in use.
}

public override void ViewDidLoad ()
{
base.ViewDidLoad ();

//Ð
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 28 Nov 2011, 09:30

I have never tried to use it from Mono Touch - but theoretically there is no difference, so it should work.

What I *think* your code is missing is the part about setting up a timer to pull responses from the API.

Unity is not thread safe - so the API per default queues up responses in the API and then your main program has to pull those to get the responses from the main thread.

You can do 2 things - either run it in non-thread safe mode, or set up a timer to poll.

Non-thread safe property on your client handler:

public bool ThreadSafeMode { get; set; }

It defaults to true. Set it to false before you connect.

Alternatively set up a timer to do this:

void FixedUpdate() {
smartFox.ProcessEvents();
}

FixedUpdate is a Unity engine callback that happens at a fixed interval. When you call ProcessEvents all queued responses will execute.

/Thomas
Full Control - maker of Unity/C# and Java SFS API and indie games
Follow on twitter: http://twitter.com/thomas_h_lund
User avatar
kotbegemot
Posts: 82
Joined: 21 Nov 2010, 05:05
Location: Saint-Petersburg

Postby kotbegemot » 30 Nov 2011, 07:01

Thanks. Are you talking about SmartFox 2.0 ? I use SmartFox 1.6.9
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 30 Nov 2011, 10:27

Ooops - yes. I was talking 2x.

For 1.x the code is:

Code: Select all

smartFox = new SmartFoxClient();
smartFox.runInQueueMode = true;

void FixedUpdate() {
smartFox.ProcessEventQueue();
}


It should default to non-queue mode where the API calls back into the client thread.

/T
Full Control - maker of Unity/C# and Java SFS API and indie games

Follow on twitter: http://twitter.com/thomas_h_lund
User avatar
kotbegemot
Posts: 82
Joined: 21 Nov 2010, 05:05
Location: Saint-Petersburg

Postby kotbegemot » 05 Dec 2011, 07:02

Yes it works Thanks !!!
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 05 Dec 2011, 07:38

Super duper!
Full Control - maker of Unity/C# and Java SFS API and indie games

Follow on twitter: http://twitter.com/thomas_h_lund

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 1 guest