chat-client/index.js

32 lines
598 B
JavaScript
Raw Normal View History

2019-03-24 17:22:44 +11:00
// Get some libraries
const net = require("net");
// Create a client
var client = new net.Socket();
function send_data(client, data)
{
// Send the data
client.write(JSON.stringify(data));
}
// Connect to the server
client.connect(22068, '127.0.0.1', function()
{
// Send some data to the server
send_data(client, {
status: "connected"
});
});
client.on('data', function(data)
{
document.getElementById('server-response').innerHTML = "Response: " + data;
});
client.on('close', function(data)
{
document.getElementById('server-response').innerHTML = "Connection closed";
});