Page 1 of 6 123 ... LastLast
Results 1 to 10 of 53

Thread: WebSocket server in C#

  1. #1
    Ext JS Premium Member amorworx's Avatar
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    70

    Thumbs up WebSocket server in C#

    Hi all!

    UPDATED!

    2010-06-29: NEW Version: refactored some stuff and included latest patches

    For those who are interested, I have desgined a websocket (Normal/SSL) server in C# (works on Mono too!) Please see attached zip file ... Please post any questions here ...
    Attached Files Attached Files
    /Cheers,

    Bert Moorthaemer
    /(bb|[^b]{2})/ that is the question ...

  2. #2
    Sencha User
    Join Date
    Jun 2010
    Posts
    22

    Default

    Hi there,

    I just take your WebSockets Server and edited it but it still doesn't work for me.

    Here is the lines I edited in the Main :

    Code:
    Server = new WebSocketServer("127.0.0.1", 81);
    Server.ClientConnected += new ClientConnectedEventHandler(OnClientConnected); // same
    Server.ClientDisconnected += new ClientDisconnectedEventHandler(OnClientDisconnected); // same
    Server.AddService("/", typeof(Service)); // same
    I launch the Server, everything is fine :
    Code:
    Service ready ...
    Hit [Enter] to stop ...
    Then I run WAMP (for fun...) and go to this page : http://localhost/WebSocketClient.html

    Which is :
    Code:
    <html>
    <head>
    <title>WebSockets</title>
    </head>
    <body>
    <script type="text/javascript">
    <!--
    	function x() 
    	{
    		var i = 0;
    		var host = "ws://127.0.0.1:81?x=1&y=2";	// "wss://127.0.0.1:81?x=1&y=2";
    		var ws = new WebSocket(host);
    
    		ws.onopen = function() {
    			//console.log("connected!");
    			//showLog("connected !");
    			document.writeln("connected !<br />");
    			ws.send("test");
    		};
    
    		ws.onclose = function() {
    			//console.log("disconnected!");
    			//showLog("disconnected !");
    			document.writeln("disconnected !<br />");
    		};
    
    		/*
    		ws.onmessage = function(evt) {
    			if (++i < 10) {
    				console.log("message received!");
    				console.dir(evt.data);
    				ws.send("pong");
    			} else {
    				document.writeln("closing" + "<br />");
    				ws.close();
    			}
    		};
    		*/
    		ws.onmessage = function (evt) { 
    			var received_msg = evt.data; 
    			document.writeln("rec = " + received_msg + "<br />");
    		};
    	};
    
    //	for (var i = 0; i < 10; i++) {
    		x();
    	//}
    -->
    </script>
    </body>
    </html>
    But directly I get disconnected (it print "disconnected !" on the web page), and I got this log in the server's console :

    Code:
    Service ready ...
    Listening on 127.0.0.1:81
    Client connected! (ID = dbe9960e-2d2b-4e07-9284-38f0dac5026a, Total = 1)
    Client disconnected! (ID = dbe9960e-2d2b-4e07-9284-38f0dac5026a, Total = 0)
    May anyone help me to stay connected? :lol:

    Thanks

    PS : Btw I'm using Chrome 5.xxx (Stable Channel) and VS2010 + .NET Framework 4
    PPS : Excuse my poor english, in fact my mother tong is french

  3. #3
    Ext JS Premium Member amorworx's Avatar
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    70

    Default

    Hi,

    That's absolutely correct behaviour ... the implementation of the WebSocket Server in this version is protocol V75. The protocol has been changed since I uploaded this version. I will replace it today with the new protocol spec. Note: some internal processing has been changed and also the exposed classes, but I think you'll find your way ...
    /Cheers,

    Bert Moorthaemer
    /(bb|[^b]{2})/ that is the question ...

  4. #4
    Sencha User
    Join Date
    Jun 2010
    Posts
    22

    Default

    Thank you very much, I look forward your implementation of the new Protocol and I thank you in advance for this great job

  5. #5
    Ext JS Premium Member amorworx's Avatar
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    70

    Default

    Hi,

    For an updated version please see my first post ...
    /Cheers,

    Bert Moorthaemer
    /(bb|[^b]{2})/ that is the question ...

  6. #6
    Sencha User
    Join Date
    Jun 2010
    Posts
    22

    Default

    Have you tested it by yourself?

    Cause the server is launching fine, but still no way to get anything except "disconnected!" from the ws client...

    And no more message in the server console.

  7. #7
    Ext JS Premium Member amorworx's Avatar
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    70

    Default

    Yes, and it works for me ...
    /Cheers,

    Bert Moorthaemer
    /(bb|[^b]{2})/ that is the question ...

  8. #8
    Sencha User
    Join Date
    Jun 2010
    Posts
    22

    Default

    Verry strange that it doesn't work for me.

    1) I compiled your code.
    2) I launched WAMP
    3) I go to your page : http://localhost/WebSockets.html
    4) Got 10x "disconnected!"

    However, the adresse is fine "localhost" and port 81 in both the JS script and in the C# code.

    Also when I close the server, you are edition a list in a foreach, you'd better not to edit a "Collection" item in a foreach statement.

    Thanks for your help

  9. #9
    Ext JS Premium Member amorworx's Avatar
    Join Date
    Jun 2008
    Location
    The Netherlands
    Posts
    70

    Default

    I'll have a look today (will test Chrome and Safari)

    BTW: Which section of the code do you mean (e.g. foreach)
    /Cheers,

    Bert Moorthaemer
    /(bb|[^b]{2})/ that is the question ...

  10. #10
    Sencha User
    Join Date
    Jun 2010
    Posts
    22

    Default

    I was wrong, the problem was when all services are removed.

    I edited your code to work fine when I close the server :

    Code:
    public void RemoveAllServices()
    {
        lock (Services)
        {
            List<string> endPoints = new List<string>();
            foreach (string endPoint in Services.Keys)
            {
                //Services[endPoint] = null;
                endPoints.Add(endPoint);
            }
            foreach (string endPoint in endPoints)
            {
                Services[endPoint] = null;
            }
    
            Services.Clear();
        }
    }
    Thanks you to look after my problem

    Maybe are I am doing something wrong?

    In this case may you tell me what do I have to do step by step in order to get your Server + JS Sample working for me?

    Regards.

Page 1 of 6 123 ... LastLast

Similar Threads

  1. Grid Extension columns and store from server from server
    By qulys in forum Ext 3.x: Help & Discussion
    Replies: 0
    Last Post: 23 Nov 2009, 2:09 AM
  2. help,how to use session in the server
    By jerome1985 in forum Ext GWT: Help & Discussion (1.x)
    Replies: 1
    Last Post: 17 Apr 2009, 2:24 AM
  3. transporting .NET server/applications upon JAVA server
    By ikonhach in forum Community Discussion
    Replies: 2
    Last Post: 1 Jul 2008, 6:54 AM
  4. what is your Server ?
    By hadikazemi in forum Ext 1.x: Help & Discussion
    Replies: 4
    Last Post: 25 Sep 2007, 2:33 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •