Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added "websocket.pl" to example scripts
- Loading branch information
Showing
9 changed files
with
63 additions
and
54 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
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 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 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 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,53 @@ | ||
#!/usr/bin/env perl | ||
|
||
# Use bundled libraries | ||
use FindBin; | ||
use lib "$FindBin::Bin/../lib"; | ||
use Mojolicious::Lite; | ||
|
||
# "Stop being such a spineless jellyfish! | ||
# You know full well I'm more closely related to the sea cucumber. | ||
# Not where it counts." | ||
any '/' => sub { | ||
my $self = shift; | ||
$self->on(message => sub { shift->send_message(shift) }) | ||
if $self->tx->is_websocket; | ||
} => 'websocket'; | ||
|
||
app->start; | ||
__DATA__ | ||
@@ websocket.html.ep | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>WebSocket</title> | ||
% my $url = url_for->to_abs->scheme('ws'); | ||
%= javascript begin | ||
var ws; | ||
if ("MozWebSocket" in window) { | ||
ws = new MozWebSocket('<%= $url %>'); | ||
} | ||
else if ("WebSocket" in window) { | ||
ws = new WebSocket('<%= $url %>'); | ||
} | ||
if(typeof(ws) !== 'undefined') { | ||
function wsmessage(event) { | ||
data = event.data; | ||
alert(data); | ||
} | ||
function wsopen(event) { | ||
ws.send("WebSocket support works!"); | ||
} | ||
ws.onmessage = wsmessage; | ||
ws.onopen = wsopen; | ||
} | ||
else { | ||
alert("Sorry, your browser does not support WebSockets."); | ||
} | ||
% end | ||
</head> | ||
<body> | ||
Testing WebSockets, please make sure you have JavaScript enabled. | ||
</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
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 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 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