WebSockets

.

Web page by Kevin Harris of Homer IL

Please contact Kevin Harris of Homer IL concerning this web site

https://www.simple-talk.com/dotnet/asp.net/asp.net-signalr-old-fashioned...
http://www.binaryintellect.net/articles/fd949e1f-dab4-4a20-938b-1e847731...

"WebSockets is a TCP-based protocol that enables bidirectional communications over a single connection."


Web Sockets

"Can I Use" list of Browsers Which Support Web Sockets

It is not easy to receive live updates in the browser because of the nature of the HTTP protocol. Historically, bidirectional communication between a client and a server required the use of HTTP to poll the server for updates. Polling with HTTP is effective, but it may involve excessive use of resources and generate excessive web traffic. Polling with HTTP is effective for applications like online chats, but it is not well suited to low latency applications (e.g. application with real time components). Polling with HTTP can consume excessive resources with it's constant request/response cycles or keep HTTP connections open for long time periods.

WebSockets is a protocol specified in the IETF document: RFC 6455 - The WebSocket Protocol which has an persistent two-way TCP connection between the client and server. Either the client or the server can start sending data at any time. The W3C published the W3C WebSocket API which enable web applications to use the WebSocket protocol. Additionally Microsoft has developed the SignalR framework for creating "real-time" web functionality using WebSockets, where available, and falling back to older transports where needed. SignalR helps protect against updates to WebSockets as it continues to update for the changes across versions of WebSockets.

Bidirectional Communications

Traditional methods of maintaining an ongoing conversation between a client and a server involved HTTP Polling and HTTP Long Polling HTTP polling uses a JavaScript timer to constantly send Ajax requests to the server at regularly scheduled times. HTTP Long Polling keeps the request open to the server until it has data to return, or times out.

The following is an example of HTTP Polling in MVC. The JavaScript is loaded in the View and it uses a timer to send Ajax requests every 3 seconds to the action method inside the controller.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
@section Scripts {
    <script type="text/javascript">
        $(document).ready(function () {
            setTimeout(CheckStatus, 3000);
        });

        function CheckStatus() {
            var options = {};
            options.url = "GetStatus";
            options.type = "POST";
            options.dataType = "json";
            options.contentType = "application/json";
            options.success = function (data) {
                if (data) {
                    $("#msg").html("<h2>Status : Found It</h2> ");
                }
                else {
                    $("#msg").html("<h2>Status : Not Found</h2> ");
                    CheckStatus();
                }
            };
            $.ajax(options);
        }
    </script>
}


JavaScript/Ajax Polling Server Every 3 Seconds

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
        [AllowAnonymous]
        public JsonResult GetStatus()
        {
            if (System.IO.File.Exists(Server.MapPath("~/flag.txt")))
            {
                return Json(true);
            }
            else
            {
                return Json(false);
            }
        }


Action Method Checking for File

SignalR

SignalR allows bi-directional communication between server and client. Servers can now push content to connected clients instantly as it becomes available. SignalR supports Web Sockets, and falls back to other compatible techniques for older browsers. SignalR includes APIs for connection management (for instance, connect and disconnect events), grouping connections, and authorization.

Error | ASP.NET Developer

Error

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /srv/disk9/1218369/www/kcshadow.net/aspnet/includes/common.inc:2748) in drupal_send_headers() (line 1232 of /srv/disk9/1218369/www/kcshadow.net/aspnet/includes/bootstrap.inc).
  • PDOException: SQLSTATE[42000]: Syntax error or access violation: 1142 INSERT command denied to user '1218369_b2cf'@'185.176.40.58' for table 'watchdog': INSERT INTO {watchdog} (uid, type, message, variables, severity, link, location, referer, hostname, timestamp) VALUES (:db_insert_placeholder_0, :db_insert_placeholder_1, :db_insert_placeholder_2, :db_insert_placeholder_3, :db_insert_placeholder_4, :db_insert_placeholder_5, :db_insert_placeholder_6, :db_insert_placeholder_7, :db_insert_placeholder_8, :db_insert_placeholder_9); Array ( [:db_insert_placeholder_0] => 0 [:db_insert_placeholder_1] => cron [:db_insert_placeholder_2] => Attempting to re-run cron while it is already running. [:db_insert_placeholder_3] => a:0:{} [:db_insert_placeholder_4] => 4 [:db_insert_placeholder_5] => [:db_insert_placeholder_6] => http://www.kcshadow.net/aspnet/?q=bidirectional [:db_insert_placeholder_7] => [:db_insert_placeholder_8] => 54.80.87.62 [:db_insert_placeholder_9] => 1534851895 ) in dblog_watchdog() (line 160 of /srv/disk9/1218369/www/kcshadow.net/aspnet/modules/dblog/dblog.module).
The website encountered an unexpected error. Please try again later.