-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Liming Xie
committed
Jun 2, 2017
1 parent
ab833e0
commit 27cc284
Showing
10 changed files
with
122 additions
and
108 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
## test-server for socket.io-unity | ||
|
||
This is a test-server written in javascript and run with node.js. | ||
|
||
## Usage | ||
|
||
```bash | ||
# install the dependencies | ||
npm install | ||
|
||
# run the server | ||
node index.js | ||
``` | ||
|
||
Now use browser to open URL `http://localhost:3000/`, then input something to interact with server. | ||
|
||
To test socket.io-unity, use socket.io code to access URL `http://localhost:3000` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title>Socket.IO chat</title> | ||
<style> | ||
* { margin: 0; padding: 0; box-sizing: border-box; } | ||
body { font: 13px Helvetica, Arial; } | ||
form { background: #000; padding: 3px; position: fixed; bottom: 0; width: 100%; } | ||
form input { border: 0; padding: 10px; width: 90%; margin-right: .5%; } | ||
form button { width: 9%; background: rgb(130, 224, 255); border: none; padding: 10px; } | ||
#messages { list-style-type: none; margin: 0; padding: 0; } | ||
#messages li { padding: 5px 10px; } | ||
#messages li:nth-child(odd) { background: #eee; } | ||
</style> | ||
</head> | ||
|
||
<script src="/socket.io/socket.io.js"></script> | ||
<script src="https://code.jquery.com/jquery-1.11.1.js"></script> | ||
<script> | ||
$(function () { | ||
var socket = io(); | ||
$('form').submit(function(){ | ||
socket.emit('chat', $('#m').val()); | ||
$('#m').val(''); | ||
return false; | ||
}); | ||
socket.on('chat', function(data){ | ||
$('#messages').append($('<li>').text("user#" + data.id + ": " + data.msg)); | ||
}); | ||
}); | ||
</script> | ||
|
||
<body> | ||
<ul id="messages"></ul> | ||
<form action=""> | ||
<input id="m" autocomplete="off" /><button>Send</button> | ||
</form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
var app = require('express')(); | ||
var http = require('http').Server(app); | ||
var io = require('socket.io')(http); | ||
|
||
app.get('/', function(req, res){ | ||
res.sendFile(__dirname + '/index.html'); | ||
}); | ||
|
||
var userId = 0; | ||
io.on('connection', function(socket){ | ||
socket.userId = userId ++; | ||
console.log('a user connected, user id: ' + socket.userId); | ||
|
||
socket.on('chat', function(msg){ | ||
console.log('message from user#' + socket.userId + ": " + msg); | ||
io.emit('chat', { | ||
id: socket.userId, | ||
msg: msg | ||
}); | ||
}); | ||
}); | ||
|
||
http.listen(3000, function(){ | ||
console.log('listening on *:3000'); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "socket.io-unity-test-server", | ||
"version": "0.0.1", | ||
"description": "test server in node.js for socket.io-unity", | ||
"dependencies": { | ||
"express": "^4.15.3", | ||
"socket.io": "^2.0.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters