Page 1 of 1

.Net C# Integration Example Needed

Posted: 22 Dec 2008, 20:31
by emaier
Good Afternoon All,

Urgent Request....

Is it possible to post a integration example or white paper on how to actually setup a connection between SFS and .Net (c#). Doesnt matter how basic it is, just being able to hook in to an event in .net is really all I need. It also doesnt matter what the project type is, winapp or web app... thanks. I have no need for Unity support.

Posted: 22 Dec 2008, 20:49
by ThomasLund
If you take a look at the Unity script code, then that should 99% be transferable to a regular C# .NET.

There will (soon after new year when I return from vacation) be some tutorials up too

Posted: 22 Dec 2008, 20:55
by emaier
When you say Unity scripts are you referencing the 3 .cs code files provided in the SFS_CSharp API download?

Posted: 23 Dec 2008, 07:33
by Lapo
Here's an example:

Code: Select all

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SmartFoxClientAPI;
using SmartFoxClientAPI.Data;

namespace SFSTest1
{
    class Program
    {
        SmartFoxClient sfs;
        
        public Program()
        {
            sfs = new SmartFoxClient();
            SFSEvent.onConnection += OnConnection;
            SFSEvent.onLogin += OnLogin;
            SFSEvent.onJoinRoom += OnJoinRoom;
			SFSEvent.onPublicMessage += OnPublicMessage;

            Trace("Connecting...");
            
            sfs.Connect("127.0.0.1", 9333);

        }

        public void OnConnection(Boolean success, String error)
        {
            if (success)
            {
                Trace("Connected");
                sfs.Login("simpleChat", "", "");
            }
            else
                Trace("Failed Connecting!");
        }

        public void OnLogin(Boolean success, String name, String error)
        {
            if (success)
            {
                Trace("LOGIN OK");
                sfs.AutoJoin();
            }

            else
                Trace("LOGIN KO!");
        }

		public void OnJoinRoom(Room room)
        {
            Trace("ROOM JOINED: " + room.GetName());
            sfs.SendPublicMessage("Hello from dotNet!");

        }

		public void OnPublicMessage(string message, User sender, int roomId)
        {
            Trace("-----> PUB MSG: " + message + ", from: " + sender.GetName());
        }

		private void Trace(string msg)
        {
            Console.WriteLine(msg);
        }

		static void Main(string[] args)
        {
            new Program();
            Console.WriteLine("Waiting for a key...");
            Console.ReadKey();
        }  
	}
}
It basically go through the initial setup:

1- connect
2- login
3- join a room

and finally send a public message.

You don't need any particular server setup as it uses the default "simpleChat" zone.

Hope it helps