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
0 parents
commit 66630b7
Showing
5 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
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,33 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<title> editor | ||
</title> | ||
<meta content="yes" name="apple-mobile-web-app-capable" /> | ||
|
||
<meta name="viewport" content="width=device-width, user-scalable=no" /> | ||
<script src="http://includes.the.tl/zepto/zepto.js"></script> | ||
<script src="http://includes.the.tl/underscore.js"></script> | ||
<script src="http://includes.the.tl/neckbrace.js"></script> | ||
<script src="http://includes.the.tl/zepto/zepto.js"></script> | ||
<script src="http://includes.the.tl/zepto/fx.js"></script> | ||
<script src="http://includes.the.tl/zepto/ajax.js"></script> | ||
<script src="http://includes.the.tl/util.js"></script> | ||
<script src="http://includes.the.tl/socket.io.js"></script> | ||
<script src="mobile-coder.js"></script> | ||
|
||
<style> | ||
* { | ||
margin:0; | ||
padding:0; | ||
} | ||
|
||
#wrapper { | ||
width: 320px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="wrapper"> | ||
</div> | ||
</body> |
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,16 @@ | ||
$(document).ready () -> | ||
|
||
ws = new WebSocket "ws://mcode.the.tl:9999/" | ||
ws.onopen = () -> | ||
console.log "open" | ||
ws.send "hahaha" | ||
ws.onmessage = (e) -> | ||
console.log e.data | ||
ws.onclose = (e) -> | ||
console.log "closed!!" | ||
ws.onerror = (e) -> | ||
console.log "error" | ||
# socket = new io.Socket("ws://mcode.the.tl:8008/") | ||
# socket.connect() | ||
# socket.send "test" | ||
|
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,19 @@ | ||
(function() { | ||
$(document).ready(function() { | ||
var ws; | ||
ws = new WebSocket("ws://mcode.the.tl:9999/"); | ||
ws.onopen = function() { | ||
console.log("open"); | ||
return ws.send("hahaha"); | ||
}; | ||
ws.onmessage = function(e) { | ||
return console.log(e.data); | ||
}; | ||
ws.onclose = function(e) { | ||
return console.log("closed!!"); | ||
}; | ||
return ws.onerror = function(e) { | ||
return console.log("error"); | ||
}; | ||
}); | ||
}).call(this); |
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,13 @@ | ||
http = require "http" | ||
io = require "socket.io" | ||
server = http.createServer (req, res) -> | ||
res.writeHeader 200, | ||
"Content-Type" : "text/html" | ||
res.end "<h1>Hello World</h1>" | ||
|
||
server.listen 8008 | ||
socket = io.listen server | ||
socket.on "connection", (client) -> | ||
info = {} | ||
client.on "message", (message) -> | ||
client.send "hi" + message |
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,51 @@ | ||
net = require "net" | ||
Server = net.Server | ||
Stream = net.Stream | ||
_ = require "underscore" | ||
root._ = _ | ||
require "zextra/util.js" | ||
|
||
hostname = "mcode.the.tl" | ||
port = 9999 | ||
|
||
location = "/" | ||
|
||
|
||
allDigits = (str) -> | ||
str.replace /\D/g, "" | ||
|
||
numberOfSpaces = (str) -> | ||
str.replace(/[^ ]/g, "").length | ||
|
||
server = new Server | ||
server.on 'connection', (stream) -> | ||
stream.on "data", (str) -> | ||
str = str.toString() | ||
console.log str.toString() | ||
if _.startsWith str, "GET / HTTP/1.1\r\nUpgrade: WebSocket\r\nConnection: Upgrade" | ||
console.log "web socket here we come" | ||
|
||
req = str.split "\r\n" | ||
for line in req | ||
if _(line).startsWith "Sec-WebSocket-Key1" | ||
key1 = _.s line, "Sec-WebSocket-Key1".length + 1 | ||
if _(line).startsWith "Sec-WebSocket-Key2" | ||
key2 = _.s line, "Sec-WebSocket-Key2".length + 1 | ||
|
||
console.log "key 1 is #{key1}" | ||
console.log "key 2 is #{key2}" | ||
|
||
#older code sir, but it doesn't checkout anymore | ||
#stream.write "HTTP/1.1 101 Web Socket Protocol Handshake\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nWebSocket-Origin: http://#{hostname}:#{port}\r\nWebSocket-Location: ws://#{hostname}:#{port}#{location}\r\n\r\n" | ||
else if _.startsWith str, "GET" | ||
content = "yo world" | ||
stream.write "HTTP/1.1 200 OK\r\n" + | ||
"Connection: close\r\n" + | ||
"Content-Type: text/html\r\n" + | ||
"Content-Length: #{content.length}\r\n\r\n" + | ||
content | ||
server.listen port | ||
#server = net.createServer (c) -> | ||
# console.log "testerson" | ||
#server.listen 1001 | ||
|