mirror of
https://github.com/PrismarineJS/node-minecraft-protocol.git
synced 2025-07-10 19:54:07 -04:00
documentation/examples for server
This commit is contained in:
parent
62e66be053
commit
e783b8a1b3
3 changed files with 146 additions and 0 deletions
examples
37
examples/server_helloworld.js
Normal file
37
examples/server_helloworld.js
Normal file
|
@ -0,0 +1,37 @@
|
|||
var mc = require('../');
|
||||
|
||||
var options = {
|
||||
'online-mode': false,
|
||||
};
|
||||
|
||||
var server = mc.createServer(options);
|
||||
|
||||
server.on('connection', function(client) {
|
||||
var addr = client.socket.remoteAddress;
|
||||
console.log('Incoming connection', '('+addr+')');
|
||||
|
||||
client.on('end', function() {
|
||||
console.log('Connection closed', '('+addr+')');
|
||||
});
|
||||
|
||||
// send init data so client will start rendering world
|
||||
client.write(0x0d, {
|
||||
x: 0,
|
||||
y: 1.62,
|
||||
stance: 0,
|
||||
z: 0,
|
||||
yaw: 0,
|
||||
pitch: 0,
|
||||
onGround: true
|
||||
});
|
||||
|
||||
client.write(0x03, { message: 'Hello, world!' });
|
||||
});
|
||||
|
||||
server.on('error', function(error) {
|
||||
console.log('Error:', error);
|
||||
});
|
||||
|
||||
server.listen(function() {
|
||||
console.log('Server listening on port', server.port);
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue