Page 1 of 1

Use Mono Api with monotouch.

Posted: 24 Nov 2011, 09:09
by kotbegemot
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


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.


[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 = "";
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 ();


Posted: 28 Nov 2011, 09:30
by ThomasLund
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() {

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


Posted: 30 Nov 2011, 07:01
by kotbegemot
Thanks. Are you talking about SmartFox 2.0 ? I use SmartFox 1.6.9

Posted: 30 Nov 2011, 10:27
by ThomasLund
Ooops - yes. I was talking 2x.

For 1.x the code is:

Code: Select all

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

void FixedUpdate() {

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


Posted: 05 Dec 2011, 07:02
by kotbegemot
Yes it works Thanks !!!

Posted: 05 Dec 2011, 07:38
by ThomasLund
Super duper!