This project is read-only.
1
Vote

when using XElement.Parse, get AppSession.cs not found

description

Hi,

(all adjusted code and the screen dumb is in the attachment)
I've been testing your code and adjusted the latest source code as followed:
Projects B-SubProtocol and SuperWebSocket where set to target .Net framework 4.5.1 instead of 4.

I added this to WebSocketServer (SuperWebSocket project)
    uint _authenticationTimeOut=1000;
    /// <summary>
    /// Max Time in milliseconds a session may use to send login credentials
    /// </summary>
    public uint AuthenticationTimeOut { get { return _authenticationTimeOut; } set { _authenticationTimeOut = value; } }
and added a Authentication method in WebSocketSession.cs (project SuperWebSocket).
    internal void OnHandshakeSuccess()
    {
        m_Handshaked = true;
        SetCookie();
        OnSessionStarted();
        AppServer.FireOnNewSessionConnected(this);
        this.Send("AUTH_REQ");
        Task.Delay((int)AppServer.AuthenticationTimeOut).ContinueWith((work) => CheckIfSessionIsAuthorizedInTime());
    }

    private void CheckIfSessionIsAuthorizedInTime()
    {
        try
        {
            if(!this.IsAuthorized)// <== set via class AUTH message handler
                this.Close();
        }
        catch { }
    }
Changed Program in B-SubProtocol to:
        var appServer = new WebSocketServer();

        appServer.AuthenticationTimeOut = 10000;
        var s = new ServerConfig();
        s.Name = "SuperWebSocket";
        s.Ip = "Any";
        s.Port = 2012;
        s.Mode = SocketMode.Tcp;
        s.MaxRequestLength = 10000000;//<== bytes?

        //Setup the appServer
        if(!appServer.Setup(s))
and changed the Test.html file to handle the message "AUTH_REQ".
(see all changes and files in the attachment authentication is just proof of concept)

The AUTH class handles the message with Keyword AUTH accordingly and works fine.

The class XLMPrices does get the message send by the htm file (JavaScript) and the message is complete. I need to process the incoming data, which is XML.
public class XMLPrices : SubCommandBase
{
    public override void ExecuteCommand(WebSocketSession session, SubRequestInfo requestInfo)
    {
        var test = XElement.Parse(requestInfo.Body.Replace("\\\"", "")).ToString(SaveOptions.DisableFormatting);
        XElement root = XElement.Load(test);

        if(session.IsAuthorized)
            session.Send("Send info: " + requestInfo.Body); //process and send result. Now just return input for test
        else
            session.Close();
    }
}
But as soon as I use
        var test = XElement.Parse(XMLInput.Replace("\\\"", "")).ToString(SaveOptions.DisableFormatting);
        XElement root = XElement.Load(test);
        test = test;
I get the error AppSession.cs not found on the first row (var test etc...). Also when I just use the second line, I get the same problem.

Everything works fine, till I start using the above. Why? How can I process the incoming message?

Problem also occurs when targeting .Net framework 4 (disabled the Task.Delay in WebSocketSession to test it.
Hope you can help me out with this issue. Furthermore it's a very nice solution ;-) Thanks for that.
Kind regards,

Matthijs

file attachments

comments

mldz wrote Jan 29, 2015 at 6:47 PM

I keep on getting this on the line with

var test = XElement.Parse(XMLInput.Replace("\\"", "")).ToString(SaveOptions.DisableFormatting);

It's trying to get this file:
d:\WorkShop\SuperSocket\v1.6\SocketBase\AppSession.cs

I think that's on one of your folders. I don't have it on my computer. Build problem?
See attachment.
Kind regards,

Matthijs

mldz wrote Jan 30, 2015 at 4:23 PM

Solved it with a try catch around the XElement in case the XML provided is not correct. Using the try catch prevents the program to search for the AppSession file.

kerryjiang wrote Jan 31, 2015 at 12:57 AM

It's your debuging problem.