Sec-WebSocket-Origin header is missing

Feb 15, 2012 at 11:31 AM

Hi

 

I configured superwebsocket but the connection closes immediately after being established with the browser

 

The error I can see in safari web inspector (safari v5.1.2) is:

"Error during WebSocket handshake: 'Sec-WebSocket-Origin' header is missing"

 

Is there something in the configuration I should setup?

 

thank you

abel

Coordinator
Feb 15, 2012 at 11:33 AM

Oh, I'll check it ASAP, if this issue does exist, I'll fix it immediately

Coordinator
Feb 15, 2012 at 11:43 AM

Got the idea, fixed it just now.

http://superwebsocket.codeplex.com/SourceControl/list/changesets

It seems that your Safari is still using hybi-00.

Feb 15, 2012 at 11:52 AM

execelent! it is working now!

thank you

 

do you know why I'm getting strange characters with chrome (v.17) ?

Using safari I receive messages just fine:

multimedia|4

using chrome I get:

mL%‼iT,♥iX5S

some characters are correct, 'm' and 'i's

Coordinator
Feb 15, 2012 at 11:56 AM

Sorry, I cannot reproduce this issue.

Just using the SuperWebSocketWeb as sample, I enter "multimedia|4", the same message can be received correctly.

Could you tell me how to reproduce it?

Feb 15, 2012 at 2:29 PM

I've tried to debug so I could understand but still can't get it.

On SuperWebSocket.WebSocketCommandInfo, line 174

Text = frame.InnerData.Decode(Encoding.UTF8, offset, length);

the result is already wrong.

Dumping the network communication:

 

GET [...]
Upgrade: websocket
Connection: Upgrade
[...]
Sec-WebSocket-Key: qsxHy+DalZKmgibZj1ZauA==
Sec-WebSocket-Version: 13

 

HTTP/1.1 101 Switching Protocols
Upgrade: WebSocket
Connection: Upgrade
Sec-WebSocket-Accept: DpXI6Vbe48hnOgx9hKfUlCIwuQc=

..."...W.o.C.i.L.4..K...&.o.".f.".....e...........
..K

Can't understand it...

Coordinator
Feb 15, 2012 at 3:06 PM

How can I reproduce it?

Feb 15, 2012 at 6:00 PM
Edited Feb 15, 2012 at 6:07 PM

I'm not sure yet,

My configuration:

  <socketServer>
    <servers>
      <server name="SuperWebSocket"
              serviceName="SuperWebSocket"
              ip="Any" port="8001" mode="Async">
      </server>
    </servers>
    <services>
      <service name="SuperWebSocket"
               type="SuperWebSocket.WebSocketServer, SuperWebSocket" />
    </services>
  </socketServer>

And source:

	public void Start()
	{
                var serverConfig = ConfigurationManager.GetSection("socketServer"as SocketServiceConfig;
                if (!SocketServerManager.Initialize(serverConfig))
                {
                    LogManager.Instance.Warn("Websocket: Failed to start! Error in configuration!");
                    return;
                }
 
                if (!SocketServerManager.Start())
                {
                    LogManager.Instance.Warn("Websocket: Failed to start!");
                    SocketServerManager.Stop();
                    return;
                }
		WebSocketServer socketServer = SocketServerManager.GetServerByName("SuperWebSocket"as WebSocketServer;
                
                socketServer.NewMessageReceived += new SessionEventHandler<WebSocketSessionstring>(socketServer_NewMessageReceived);
                socketServer.NewSessionConnected += new SessionEventHandler<WebSocketSession>(socketServer_NewSessionConnected);
                socketServer.SessionClosed += new SessionEventHandler<WebSocketSessionCloseReason>(socketServer_SessionClosed);
	}
        void socketServer_NewSessionConnected(WebSocketSession session)
        {
            lock (m_SessionSyncRoot)
                m_Sessions.Add(session);
        }
        void socketServer_SessionClosed(WebSocketSession session, CloseReason reason)
        {
            lock (m_SessionSyncRoot)
            {
                m_Sessions.Remove(session);
            }
        }
        void socketServer_NewMessageReceived(WebSocketSession session, string e)
        {
            lock (m_SessionSyncRoot)
            {
                ProcessMessage(e);
            }
        }

Is there something strange with the code?

I get the strange strings in:

 socketServer_NewMessageReceived
Coordinator
Feb 16, 2012 at 12:18 AM

I mean how you test it? By browser? Which browser and what did you send to server?

Feb 16, 2012 at 8:24 AM

Hi

yes, by browser, using chrome v17

websocket is opened using:

	connection = new WebSocket(websocketurl);
	

and messages are sent using:

	connection.send(txt);

using safari it works fine

anything i send with chrome, I receive in superwebsocket with many characters garbled.

Coordinator
Feb 16, 2012 at 8:25 AM

Oh,  sorry, I cannot reproduce it.

Coordinator
Feb 16, 2012 at 8:27 AM

And which version of SuperWebSocket are you using?

And what;s your webpage's encoding, to simplify the problem, please use utf8 encoding page.

Feb 16, 2012 at 8:35 AM

I'm using superwebsocket v.73070

I'm using utf8 for the page encoding

Coordinator
Feb 17, 2012 at 2:20 AM

Do you mind share your code with me?

kerry-jiang@hotmail.com

Feb 17, 2012 at 6:40 PM
Edited Feb 17, 2012 at 6:45 PM

Hi

Chrome 17.0.963.56 m

Safari 5.1.2 (7534.52.7)

 

The server part is

 

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using SuperSocket.SocketEngine;
using SuperWebSocket;
using SuperSocket.SocketEngine.Configuration;
using SuperSocket.SocketBase;

namespace SWSTest
{
    class Program
    {

        
        private static List<WebSocketSession> m_Sessions = new List<WebSocketSession>();
        private static object m_SessionSyncRoot = new object();

        static void Main(string[] args)
        {
            
            try
            {
                var serverConfig = ConfigurationManager.GetSection("socketServer") as SocketServiceConfig;
                if (!SocketServerManager.Initialize(serverConfig))
                {
                    Console.WriteLine("Websocket: Failed to start! Error in configuration!");
                    return;
                }

                if (!SocketServerManager.Start())
                {
                    Console.WriteLine("Websocket: Failed to start!");
                    SocketServerManager.Stop();
                    return;
                }

                try
                {
                    WebSocketServer socketServer = SocketServerManager.GetServerByName("SuperWebSocket") as WebSocketServer;

                    socketServer.NewMessageReceived += new SessionEventHandler<WebSocketSession, string>(socketServer_NewMessageReceived);
                    socketServer.NewSessionConnected += new SessionEventHandler<WebSocketSession>(socketServer_NewSessionConnected);
                    socketServer.SessionClosed += new SessionEventHandler<WebSocketSession, CloseReason>(socketServer_SessionClosed);

                }
                catch (Exception)
                {
                    Console.WriteLine("Websocket: Failed to start! Error while setting delegates!");
                    Stop();
                    return;
                }

                Console.WriteLine("Websocket: Server has started...");
            }
            catch (Exception)
            {
                Stop();
            }
        }
            
        static void Stop()
        {
            try
            {
                SocketServerManager.Stop();

                Console.WriteLine("Websocket: Server has stopped...");
            }
            catch (Exception)
            {
                //ignore
            }
        }
        

        static void socketServer_NewSessionConnected(WebSocketSession session)
        {
            lock (m_SessionSyncRoot)
                m_Sessions.Add(session);
        }

        static void socketServer_SessionClosed(WebSocketSession session, CloseReason reason)
        {
            lock (m_SessionSyncRoot)
            {
                if (m_Sessions.Contains(session) == false)
                {
                    session.Close();
                    return;
                }
                m_Sessions.Remove(session);
            }
        }



        static void socketServer_NewMessageReceived(WebSocketSession session, string e)
        {
            lock (m_SessionSyncRoot)
            {
                if (m_Sessions.Contains(session))
                {
                    Console.WriteLine(e);
                }
            }
        }
    }

}

 

The server app.config is

 

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="socketServer" type="SuperSocket.SocketEngine.Configuration.SocketServiceConfig, SuperSocket.SocketEngine"/>
  </configSections>
  <socketServer>
    <servers>
      <server name="SuperWebSocket"
              serviceName="SuperWebSocket"
              ip="Any" port="8001" mode="Async">
      </server>
    </servers>
    <services>
      <service name="SuperWebSocket"
               type="SuperWebSocket.WebSocketServer, SuperWebSocket" />
    </services>
  </socketServer>
</configuration>

 

The html/js part is

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <script type="text/javascript" >
            
			var server_address = location.hostname;
			var websocketurl = 'ws://' + server_address + ':8001/SuperWebSocket';
			
			websocket = new WebSocket(websocketurl);
			
			
			websocket.onopen = function(e){
				websocket.send("abcdefghijklmnopqrstuvwxyz");
			};
		</script>
	</head>
	<body>
	Test
	</body>
</html>

 

 

The output of the server connecting first with chrome and then safari:

 

Websocket: Server has started...
a??e{??iw??ms??qo??uk??yg
abcdefghijklmnopqrstuvwxyz
Feb 27, 2012 at 8:37 AM

Hi

 

Can you reproduce the error?

 

Regards

Coordinator
Feb 28, 2012 at 12:42 AM

I cannot produce it.

 

It goes well.

* Connecting to server ..
* Connection open
# System: Kerry connected
# Kerry: abcdefghijklmnopqrstuvwxyz
* Secure Connection open
# Push data from WebSocket. [0] Current Time: 2/28/2012 9:39:32 AM
# Push data from WebSocket. [1] Current Time: 2/28/2012 9:39:37 AM

 

I tried to produce it by:

Changed the code in sample website SuperWebSocketWeb:

ws.onopen = function () {
                messageBoard.append('* Connection open<br/>');
            };

=>

ws.onopen = function () {
                ws.send("abcdefghijklmnopqrstuvwxyz");
                messageBoard.append('* Connection open<br/>');
            };

Coordinator
Feb 28, 2012 at 1:01 AM

Could you check your file encoding?

 

File -> Advanced Save Options -> UTF8 with signature

Feb 28, 2012 at 2:14 PM

I have it with UTF8 with BOM in VS and the html file is UT8 without BOM

 

I also tried with FF 11 and it gives me the same problem, so at the moment I can only use safari.

 

I'll look a little more into it at the end of the week.

Coordinator
Feb 29, 2012 at 12:28 AM

Which version of SuperWebSocket are you using? Did you configure the SuperWebSocket with a special value?

You can send the full source code in a package, so that I can help you figure out the issue.

BTW, could you try run the sample project SuperWebSocketWeb and then change some code base on it?

Mar 5, 2012 at 11:15 AM

Hi

I tried with the downloaded binaries instead of compiling the sources and it works.

Don't know what I was doing to the sources to make it behave like that.

Thank you for your support

Coordinator
Mar 5, 2012 at 11:32 AM
Good news!

Sent from my Windows Phone

From: abel_silva
Sent: 3/5/2012 8:15 PM
To: kerry-jiang@hotmail.com
Subject: Re: Sec-WebSocket-Origin header is missing [SuperWebSocket:316332]

From: abel_silva

Hi

I tried with the downloaded binaries instead of compiling the sources and it works.

Don't know what I was doing to the sources to make it behave like that.

Thank you for your support