add socket connection

This commit is contained in:
Asraelite 2016-03-21 14:19:22 +00:00
parent 1de440cedb
commit 9787a9d468
9 changed files with 7302 additions and 9 deletions

View file

@ -4,9 +4,13 @@
<meta charset="UTF-8">
<link rel="icon" type="image/png" href="img/favicon.png">
<link rel="stylesheet" type="text/css" href="css/styles.css">
<title>
Starbugs
</title>
<script src="js/lib/socket.io.js"></script>
<script src="starbugs.min.js"></script>
</head>
<body>

7252
public/js/lib/socket.io.js Normal file

File diff suppressed because it is too large Load diff

View file

@ -2,6 +2,8 @@
window.addEventListener('load', init);
function init() {
var socket;
function init() {
socket = io.connect('http://localhost:8080');
}

View file

@ -1,14 +1,14 @@
'use strict';
const socketio = require('socket.io');
const GameNet = require('./net');
class GameServer {
constructor() {
constructor(webServer) {
this.net = new GameNet();
}
start() {
this.net.listen();
}
}

View file

@ -0,0 +1,9 @@
'use strict';
class Connection {
constructor() {
}
}
module.exports = Connection;

View file

25
server/game/net/index.js Normal file
View file

@ -0,0 +1,25 @@
'use strict';
const socketio = require('socket.io');
const Connection = require('./connection.js');
class GameNet {
constructor() {
this.io = socketio(starbugs.webServer.appServer);
}
listen() {
let io = this.io;
this.io.on('connection', socket => {
console.log('connection');
socket.on('other event', data => {
console.log(data);
});
});
}
}
module.exports = GameNet;

View file

View file

@ -1,16 +1,19 @@
'use strict';
const express = require('express');
const http = require('http');
const minify = require('./minify.js');
class WebServer {
constructor() {
this.app = express();
this.appServer = http.Server(this.app);
}
start() {
this.app = express();
this.appServer.listen(8080);
let app = this.app;
app.get('/starbugs.min.js', (req, res) => {
@ -21,8 +24,6 @@ class WebServer {
});
app.use(express.static('public'));
app.listen(8080);
}
}