Custom Session Implementation

Sep 7, 2011 at 12:28 AM

I am occupying a CustomSession named INLSession this done based on the sample project you posted, but when I try to initialize it by configuration (StartSuperWebSocketByConfig) in global.asax in the code:

var serverConfig = ConfigurationManager.GetSection("socketServer") as SocketServiceConfig;
            if (!SocketServerManager.Initialize(serverConfig)) //==> in this part always returns false
                return;
please help!!
thanks in advance

Sep 7, 2011 at 1:06 AM

I am having the same problem.

I just tried copying over the Config/log4net.config file over to my project and it did not seem to help.

I will try a few more things here tonight and let you know.

Sep 7, 2011 at 1:39 AM

OK not sure if you have the same issue but commented out the secure line in the web.config for now and it started working for me. I have much of the secure code from the example commented out for now until I get a chance to learn the system better. Once I commented this line in the web.config, it started to work for me! I figured it has something to do with the config file since it always returned false...

 <!-- <server name="SecureSuperWebSocket"                    serviceName="SuperWebSocket"                    ip="Any" port="2032" mode="Sync" security="tls">                install the certificate to your trusted certificates store, the password is 'supersocket'                <certificate filePath="localhost.pfx"                             password="supersocket"                             isEnabled="true"></certificate>            </server>-->     

Sep 7, 2011 at 1:41 AM
Edited Sep 7, 2011 at 1:42 AM

Maybe its because I didnt copy over the cert, localhost.pfx file.

Sep 7, 2011 at 2:08 AM

Check the log files in directory "Logs"

Sep 7, 2011 at 2:28 AM
Edited Sep 7, 2011 at 2:36 AM

 

Kidsysco


Thanks for trying to help me, but the solution that your plants are not served me, look, here is all the code that follows the problem
 Assembly Project CustomSession
namespace SuperWebSocket.Samples.CustomSession
{
    public class CRMAppServer : WebSocketServer<CRMSession>
    {
        //Because the sample process requests by sub protocol, so passing sub protocol instance to parent class in the line below is required
        public CRMAppServer()
            : base(new BasicSubProtocol<CRMSession>(new List<Assembly>{ typeof(CRMAppServer).Assembly }))           
        {

        }
    }
}

 

namespace SuperWebSocket.Samples.CustomSession
{
    public class CRMSession : WebSocketSession<CRMSession>
    {
        public int CompanyId { get; private set; }

        protected override void OnHandShaked()
        {
            int companyId;

            //read companyId from cookie
            if (int.TryParse(Cookies["companyId"], out companyId))
                CompanyId = companyId;
        }
    }
}

namespace SuperWebSocket.Samples.CustomSession.JsonObject
{
    public class BroadcastMessage
    {
        public int CompanyId { get; set; }

        public string Content { get; set; }
    }
}

namespace SuperWebSocket.Samples.CustomSession.Command
{
    /// <summary>
    /// Broadcast messages to sessions below to specific company
    /// </summary>
    public class BRCT : JsonSubCommand<CRMSession, BroadcastMessage>
    {
        protected override void ExecuteJsonCommand(CRMSession session, BroadcastMessage commandInfo)
        {
            if (commandInfo.CompanyId <= 0)
                return;

            string message = "MSG " + SerializeObject(commandInfo);

            foreach(var s in session.AppServer.GetSessions(s => s.CompanyId == commandInfo.CompanyId))
            {
                s.SendResponseAsync(message);
            }
        }
    }
}

Project Web (SuperWebSocketWeb)
Web.Config

<appSettings>
    <add key="ServiceName" value="SuperWebSocket"/>
  </appSettings>
    <socketServer>
        <servers>
            <server name="SuperWebSocket"
                    serviceName="CRMWebSocketService"
                    ip="Any" port="2011" mode="Async"
      commandAssembly="SuperWebSocket.Samples.CustomSession">
            </server>
            <server name="SecureSuperWebSocket"
                    serviceName="CRMWebSocketService"
                    ip="Any" port="2012" mode="Sync" security="tls"
      commandAssembly="SuperWebSocket.Samples.CustomSession">
                <!--Please install the certificate to your trusted certificates store, the password is 'supersocket'-->
                <certificate filePath="supersocket.pfx"
                             password="supersocket"
                             isEnabled="true"></certificate>
            </server>
        </servers>
        <services>
            <service name="CRMWebSocketService"
                     type="SuperWebSocket.Samples.CustomSession.CRMAppServer, SuperWebSocket.Samples.CustomSession" />
        </services>
    </socketServer>


Global.asax
 var serverConfig = ConfigurationManager.GetSection("socketServer") as SocketServiceConfig;
            if (!SocketServerManager.Initialize(serverConfig)) //==> in this part always returns false
                return;

 


please help!

Sep 7, 2011 at 2:47 AM

kerryjiang

i checked directory Logs and i don't have any errors, the only record I have is the file info.log, it says

09/05/2011 22:21:29,914 [7] INFO SuperSocket - SuperWebSocket has been started
09/05/2011 22:21:29,958 [7] INFO SuperSocket - SecureSuperWebSocket has been started
09/05/2011 22:24:01,506 [15] INFO SuperSocket - SuperWebSocket Has Been Stopped
09/05/2011 22:24:01,606 [15] INFO SuperSocket - SecureSuperWebSocket Has Been Stopped

Sep 7, 2011 at 2:51 AM

Check error log

Sep 7, 2011 at 2:58 AM

i don't have any record in error.log

Sep 7, 2011 at 3:02 AM
Could you debug into it? You should have all source code to debug.

From: [email removed]
Sent: Wednesday, September 07, 2011 7:28 AM
To: [email removed]
Subject: Custom Session [SuperWebSocket:271684]

From: mlhoo

I am occupying a CustomSession named INLSession this done based on the sample project you posted, but when I try to initialize it by configuration (StartSuperWebSocketByConfig) in global.asax in the code:

var serverConfig = ConfigurationManager.GetSection("socketServer") as SocketServiceConfig;
            if (!SocketServerManager.Initialize(serverConfig)) //==> in this part always returns false
                return;
please help!!
thanks in advance

Sep 7, 2011 at 3:41 AM
Edited Sep 7, 2011 at 3:43 AM

Yes, i can debug without any problem, therefore always returns as the result of the method SocketServerManager.Initialize (ServerConfig) is always false

Sep 7, 2011 at 4:00 AM

No, debug's purpose is to find out why initialization return false. 

Sep 7, 2011 at 4:04 AM

Oh, i am sorry, Not because the method SocketServerManager.Initialize (ServerConfig) is part of SuperSocket.SocketEngine.dll assembly, therefore I can not debug

Sep 7, 2011 at 4:10 AM

It is strange that you didn't get the error log.

Where you put the line LogUtil.Setup();

Sep 7, 2011 at 4:19 AM

in Application_Start i put the line LogUtil.Setup();

protected void Application_Start()
        {

            LogUtil.Setup();
            StartSuperWebSocketByConfig();
            //StartSuperWebSocketByProgramming();
            

           
        }

 

 

Sep 7, 2011 at 4:21 AM

Oh, you need to get the source code of SuperSocket and then debug into the code.

Get the SuperSocket 1.4 stable from http://supersocket.codeplex.com/.

I am sorry...

Sep 7, 2011 at 5:26 AM
Edited Sep 7, 2011 at 5:26 AM

Kerryjiang , i solved the problem, in the web.config remove attribute commandAssembly="SuperWebSocket.Samples.CustomSession", I was reading the assembly twice, so I doubled the SubCommands

Logger.LogError (String.Format ("You have defined duplicated command {0} command in your assembly!" Command.Name));
return false;

seemingly enough to define only once and in one place in the web.config custom assembly.

<appSettings>
<add key="ServiceName" value="SuperWebSocket"/>
</appSettings>
<socketServer>
<servers>
<server name="SuperWebSocket"
serviceName="CRMWebSocketService"
ip="Any" port="2011" mode="Async"
commandAssembly="SuperWebSocket.Samples.CustomSession"> // I REMOVE THIS ATTRIBUTE
</server>
<server name="SecureSuperWebSocket"
serviceName="CRMWebSocketService"
ip="Any" port="2012" mode="Sync" security="tls"
commandAssembly="SuperWebSocket.Samples.CustomSession">
<!--Please install the certificate to your trusted certificates store, the password is 'supersocket'-->
<certificate filePath="supersocket.pfx"
password="supersocket"
isEnabled="true"></certificate>
</server>
</servers>
<services>
<service name="CRMWebSocketService"
type="SuperWebSocket.Samples.CustomSession.CRMAppServer, SuperWebSocket.Samples.CustomSession" /> //HERE IS ALREADY DEFINED
</services>
</socketServer>

 

THANKS FOR YOU HELP

Sep 7, 2011 at 5:30 AM

Yeah, I am confused why error log doesn't work for you.