Skip to content
Permalink
 
 
Cannot retrieve contributors at this time
65 lines (56 sloc) 1.89 KB
@{
ViewData["Title"] = "Home Page";
}
<div class="row">
<div class="col-md-6">
<h2>Web Sockets with Xamarin Forms!</h2>
<form>
<div class="form-group">
<label for="message">Message:</label>
<textarea id="message" class="form-control" rows="3"></textarea>
</div>
<button id="sendMessage" class="btn btn-default">Send</button>
</form>
<div style="margin-top: 15px;">
<h4>Status:</h4>
<div style="background: #f0f0f0; border: solid 1px #999;padding:6px" id="status"></div>
<h4>Data:</h4>
<div style="background: #f0f0f0; border: solid 1px #999;padding:6px" id="data"></div>
</div>
</div>
<div class="col-md-6">
</div>
</div>
@section scripts{
<script>
var webSocket;
$().ready(function () {
webSocket = new WebSocket("ws://localhost:53273/");
webSocket.onopen = function () {
$("#status").text("connected");
};
webSocket.onmessage = function (evt) {
$("#data").append("<p>" + evt.data + "</p>");
};
webSocket.onerror = function (evt) {
alert(evt.message);
};
webSocket.onclose = function () {
$("#status").text("disconnected");
};
$("#sendMessage").click(function () {
if (webSocket.readyState == WebSocket.OPEN) {
webSocket.send($("#message").val());
$("#message").val("");
$("#message").focus();
}
else {
$("status").text("Connection is closed");
}
});
$("form").submit(function (e) {
e.preventDefault(e);
});
});
</script>
}
You can’t perform that action at this time.