Websocket Box Test

Developer
Size
2,518 Kb
Views
10,120

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 Previews

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 +"}") }
}
Websocket Box Test - Script Codes
Websocket Box Test - Script Codes
Home Page Home
Developer Leo
Username theLMGN
Uploaded January 19, 2023
Rating 3
Size 2,518 Kb
Views 10,120
Do you need developer help for Websocket Box Test?

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!

Leo (theLMGN) Script Codes
Name
DJ5K
Game Start Page
Fidget Spinner
Skycade Reset Counter
Vivaldi Ad Slider
Ale
File64
A Pen by Leo
GIF player thingy
Maths.
Create amazing captions with AI!

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!