.Net C# Integration Example Needed

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

Moderators: Lapo, Bax

emaier
Posts: 8
Joined: 12 Dec 2008, 20:22

.Net C# Integration Example Needed

Postby emaier » 22 Dec 2008, 20:31

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.
ThomasLund
Posts: 1297
Joined: 14 Mar 2008, 07:52
Location: Sweden

Postby ThomasLund » 22 Dec 2008, 20:49

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
emaier
Posts: 8
Joined: 12 Dec 2008, 20:22

Postby emaier » 22 Dec 2008, 20:55

When you say Unity scripts are you referencing the 3 .cs code files provided in the SFS_CSharp API download?
User avatar
Lapo
Site Admin
Posts: 23026
Joined: 21 Mar 2005, 09:50
Location: Italy

Postby Lapo » 23 Dec 2008, 07:33

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
Lapo
--
gotoAndPlay()
...addicted to flash games

Return to “.Net / Unity3D API”

Who is online

Users browsing this forum: No registered users and 35 guests