Commit dcbd1cbb authored by Sergey Lyubka's avatar Sergey Lyubka

Moved pubsub example to websocket_chat

parent a3b568f4
# Copyright (c) 2014 Cesanta Software
# All rights reserved
PROG = websocket_chat
CFLAGS = -W -Wall -I../.. -g -O0 $(CFLAGS_EXTRA)
SOURCES = $(PROG).c ../../mongoose.c
$(PROG): $(SOURCES)
$(CC) -o $(PROG) $(SOURCES) $(CFLAGS)
clean:
rm -rf $(PROG) *.exe *.dSYM *.obj *.exp .*o *.lib
...@@ -48,7 +48,7 @@ ...@@ -48,7 +48,7 @@
document.getElementById('messages').appendChild(div); document.getElementById('messages').appendChild(div);
} }
}; };
window.onload = function() { window.onload = function() {
document.getElementById('send_button').onclick = function(ev) { document.getElementById('send_button').onclick = function(ev) {
var msg = document.getElementById('send_input').value; var msg = document.getElementById('send_input').value;
...@@ -74,7 +74,7 @@ ...@@ -74,7 +74,7 @@
connection with Mongoose, making each browser window a websocket client. connection with Mongoose, making each browser window a websocket client.
Join a room, send messages, and see messages sent by other clients. Join a room, send messages, and see messages sent by other clients.
</p> </p>
<p> <p>
My ID: <b><span id="my_id"></b></span> My ID: <b><span id="my_id"></b></span>
</p> </p>
...@@ -88,7 +88,7 @@ ...@@ -88,7 +88,7 @@
<div id="messages"> <div id="messages">
</div> </div>
<p> <p>
<input type="text" id="send_input" /> <input type="text" id="send_input" />
<button id="send_button">Send Message</button> <button id="send_button">Send Message</button>
......
...@@ -46,7 +46,7 @@ static int ev_handler(struct mg_connection *conn, enum mg_event ev) { ...@@ -46,7 +46,7 @@ static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
handle_websocket_message(conn); handle_websocket_message(conn);
return MG_TRUE; return MG_TRUE;
} else { } else {
mg_send_file(conn, "pubsub.html"); // Return MG_MORE after mg_send_file() mg_send_file(conn, "index.html"); // Return MG_MORE after mg_send_file()
return MG_MORE; return MG_MORE;
} }
case MG_WS_CONNECT: case MG_WS_CONNECT:
...@@ -67,10 +67,10 @@ static int ev_handler(struct mg_connection *conn, enum mg_event ev) { ...@@ -67,10 +67,10 @@ static int ev_handler(struct mg_connection *conn, enum mg_event ev) {
int main(void) { int main(void) {
s_server = mg_create_server(NULL, ev_handler); s_server = mg_create_server(NULL, ev_handler);
mg_set_option(s_server, "listening_port", "8080"); mg_set_option(s_server, "listening_port", "8080");
signal(SIGTERM, signal_handler); signal(SIGTERM, signal_handler);
signal(SIGINT, signal_handler); signal(SIGINT, signal_handler);
printf("Started on port %s\n", mg_get_option(s_server, "listening_port")); printf("Started on port %s\n", mg_get_option(s_server, "listening_port"));
while (s_signal_received == 0) { while (s_signal_received == 0) {
mg_poll_server(s_server, 100); mg_poll_server(s_server, 100);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment