Websocket Box Test
How do I make an websocket box test?
What is a websocket box test? How do you make a websocket box test? This script and codes were developed by Leo on 19 January 2023, Thursday.
Websocket Box Test - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>Websocket Box Test</title> <link rel="stylesheet" href="css/style.css">
</head>
<body> x offset: <input type="number" id="xo" value="0"></input> y offset: <input type="number" id="yo" value="0"></input><button onClick="resetPos()">Reset pos</button>
<div id="raw"></div>
<div id="block"></div> <script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js'></script> <script src="js/index.js"></script>
</body>
</html>
Websocket Box Test - Script Codes CSS Codes
#raw { right: 0; opacity: 80%; z-index: 2; bottom: 0; position: absolute;
}
#block { width: 1vw; height: 1vh; position: absolute; z-index: 1; background: #000;
}
input,button { z-index: 10;
}
body { overflow: hidden;
}
Websocket Box Test - Script Codes JS Codes
//gayQuery: Write More, Do Less
function get(id) { return document.getElementById(id)
} var noSupportMessage = "Your browser does not support WebSockets!"; var ws; function appendMessage(message) { $('#raw').append(message + "<br>"); } function connectSocketServer(ip) { console.info("Connecting to " + ip) var support = "MozWebSocket" in window ? 'MozWebSocket' : ("WebSocket" in window ? 'WebSocket' : null); if (support == null) { appendMessage("* " + noSupportMessage); return; } appendMessage("* Connecting to server .."); // create a new websocket and connect ws = new window[support](ip); //please no ddos TANNNNKS // when data is comming from the server, this metod is called ws.onmessage = function (evt) { appendMessage("# " + evt.data); var p = JSON.parse(evt.data); get("block").style.left = (p.left - get("xo").value) + "vw"; get("block").style.top = (p.top - get("yo").value) +"vh"; }; // when the connection is established, this method is called ws.onopen = function () { appendMessage("connected") }; // when the connection is closed, this method is called ws.onclose = function () { appendMessage("disconnected") } } connectSocketServer("ws://127.0.0.1:8000")
function resetPos() { ws.send("{\"left\": 0,\"top\": 0}")
}
document.onkeydown = checkKey;
function checkKey(e) { e = e || window.event; var x = Number(get("block").style.left.replace("vw","")); var y = Number(get("block").style.top.replace("vh","")) if (e.keyCode == '38') { ws.send("{\"left\": " + x +",\"top\": " + parseInt(y - 1, 10) +"}") } else if (e.keyCode == '40') { ws.send("{\"left\": " + x +",\"top\": " + parseInt(y + 1, 10) +"}") } else if (e.keyCode == '37') { ws.send("{\"left\": " + parseInt(x - 1, 10) +",\"top\": " + y +"}") } else if (e.keyCode == '39') { ws.send("{\"left\": " + parseInt(x + 1, 10) +",\"top\": " + y +"}") }
}
Developer | Leo |
Username | theLMGN |
Uploaded | January 19, 2023 |
Rating | 3 |
Size | 2,518 Kb |
Views | 10,120 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
DJ5K | 5,458 Kb |
Game Start Page | 2,287 Kb |
Fidget Spinner | 1,770 Kb |
Skycade Reset Counter | 3,124 Kb |
Vivaldi Ad Slider | 2,026 Kb |
Ale | 1,593 Kb |
File64 | 3,515 Kb |
A Pen by Leo | 4,909 Kb |
GIF player thingy | 8,756 Kb |
Maths. | 1,549 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
SVG email test v2.0 | M_J_Robbins | 2,090 Kb |
Bootstrap 4 Gridsystem Demo | Rivella50 | 1,535 Kb |
Minimelephant | Smashlee | 2,507 Kb |
FontAwesome icons with animation | Nicotinell | 2,083 Kb |
Background Images | Jooonebug | 2,100 Kb |
Flexbox slider | Rendro | 3,459 Kb |
Google Fonts Sass Mixin | HugoGiraudel | 4,237 Kb |
A Pen by Moeid Saleem | Moeidsaleem | 1,862 Kb |
HTML5 Video Autoplay | Zivcos | 1,352 Kb |
Svg animation draw | SzymonDziewonski | 5,545 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!