-
-
Save Joemires/ee65d612a9f044534015986cc2fe9a1f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<html> | |
<head> | |
<title>client</title> | |
<script src="http://localhost:8888/socket.io/socket.io.js"></script> | |
<script type="text/javascript"> | |
var socket = new io.Socket('localhost'); | |
socket.connect(); | |
socket.on('connect', function() | |
{ | |
console.log('connected'); | |
socket.emit('data',{test : 'awd'}); | |
}); | |
socket.on('data',function(args) | |
{ | |
console.log('got:'); | |
console.log(data); | |
}); | |
socket.on('disconnect', function() | |
{ | |
console.log('disconnected'); | |
}); | |
</script> | |
</head> | |
<body> | |
</body> | |
</html> |
This file contains hidden or 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
var http = require('http'), | |
io = require('socket.io'), | |
fs = require('fs'), | |
server = http.createServer(function(request, response) | |
{ | |
if(request.url != '/favicon.ico' && request.url != '/socket.io/socket.io.js') | |
{ | |
fs.readFile('./client.html', function(error, content) | |
{ | |
if (error) | |
{ | |
console.log('error sending client!'); | |
response.writeHead(500); | |
response.end(); | |
} | |
else | |
{ | |
response.writeHead(200, { 'Content-Type': 'text/html' }); | |
response.end(content, 'utf-8'); | |
} | |
}); | |
} | |
}); | |
server.listen(8888); | |
var socket = io.listen(server); | |
socket.on('connection',function(client) | |
{ | |
}); | |
socket.on('data',function(data) | |
{ | |
console.log(data); | |
socket.emit('right back atcha'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment