Note that there are some explanatory texts on larger screens.

plurals
  1. POBasic Html5 Socket issue
    primarykey
    data
    text
    <p>Just wondering if some can help me with the issue, below is my web socket Helloserver code and the client.htm code. After starting the Helloserver we run the client and notice that it does not connect to the server, will really appreciate if someone can help.</p> <p>Here is the client.htm:</p> <pre><code>&lt;!doctype html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Web Sockets: Connecting to the Server&lt;/title&gt; &lt;link rel="Stylesheet" href="/global.css" type="text/css" /&gt; &lt;/head&gt; &lt;body&gt; &lt;div id="container"&gt; &lt;h1&gt;Connecting to Web Socket Server&lt;/h1&gt; &lt;ul id="log"&gt;&lt;/ul&gt; &lt;/div&gt; &lt;/body&gt; &lt;script src="../scripts/jquery-1.7.2.js" type="text/javascript"&gt;&lt;/script&gt; &lt;script&gt; $(function () { function logMsg(message) { $("#log").append("&lt;li&gt;" + message + "&lt;/li&gt;"); } logMsg("Attempting to connect to socket server"); var server = null; try { server = new WebSocket("ws://localhost:8181/server"); server.addEventListener("message", messageHandler, false); server.addEventListener("open", openHandler, false); server.addEventListener("close", closeHandler, false); } catch (e) { } function openHandler(e) { logMsg("Connection opened"); } function closeHandler(e) { logMsg("Connection closed"); } function messageHandler(e) { logMsg("Server says: " + e.data); } }); &lt;/script&gt; &lt;/html&gt; </code></pre> <p>Here is the server code:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using SocketServer.Models; using Nugget; namespace SocketServer { class HelloServer : ISocketServer { private string _serverPath = string.Empty; private WebSocketServer _server = null; private string _input = string.Empty; public string Input { set { this._input = value; } } public void Initialize(string serverPath, string originServerAndPort) { this._server = new WebSocketServer(8181, originServerAndPort, "ws://localhost:8181"); this._server.RegisterHandler&lt;Socket&gt;(serverPath); Nugget.Log.Level = LogLevel.None; } public void Start() { this._server.Start(); } public void Send() { this._server.SendToAll(this._input); } } } </code></pre> <p>Here is the console code to start the server:</p> <pre><code>using System; using Nugget; namespace SocketServer { class Server { static void Main(string[] args) { ISocketServer server = null; Console.WriteLine(); Console.WriteLine("Welcome to the socket server."); Console.WriteLine(); Console.WriteLine("Which server type would you like to create?"); Console.WriteLine(" 1) Hello World Server"); Console.WriteLine(" 2) Stocks Server"); Console.WriteLine(); string input = Console.ReadLine(); if (input == "1") { server = new HelloServer(); server.Initialize("/server", "http://localhost:2709"); Console.WriteLine(""); Console.WriteLine("The Hello World Server is now available under ws://localhost:8181/server."); Console.WriteLine(""); } else if (input == "2") { server = new StockServer(); server.Initialize("/stocks", "http://localhost:2709"); Console.WriteLine(""); Console.WriteLine("The Stocks Server is now available under ws://localhost:8181/stocks."); Console.WriteLine(""); } else { Console.WriteLine(""); Console.WriteLine(string.Format("Sorry, {0} is not a valid option.", input)); Console.WriteLine(""); } if (server != null) { server.Start(); input = string.Empty; while (input != "exit") { server.Input = input; server.Send(); input = Console.ReadLine(); } } Console.WriteLine(""); Console.WriteLine("Closing socket server."); Console.WriteLine(""); } } } </code></pre> <p>The issue we are having is that after the client is run it gives this message and does not connect to the server:</p> <pre> Attempting to connect to socket server Connection closed </pre> <p>Any help will be appreciated.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload