JSFiddle - React, Tailwind, and code Playground
by Amit Pandya
HTML
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>
JavaScript
var print_label_url = "http://10.11.12.50:9100";
var print_lbl_data = "^XA^LT05^FO05,10^A3N,50,50^FDTGHU0816326^FS^XZ";
// Create a socket instance
var socket = new WebSocket('ws://10.11.12.50:9100');
// Open the socket
socket.onopen = function(event) {
// Send an initial message
socket.send(print_lbl_data);
// Listen for messages
socket.onmessage = function(event) {
console.log('Client received a message',event);
};
// Listen for socket closes
socket.onclose = function(event) {
console.log('Client notified socket has closed',event);
};
// To close the socket....
socket.close()
};