Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongoose
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
esp
mongoose
Commits
e84d0574
Commit
e84d0574
authored
Sep 29, 2013
by
Sergey Lyubka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed websocket example logic when freeing the message
parent
1a64d37f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
3 deletions
+6
-3
websocket.c
examples/websocket.c
+6
-3
No files found.
examples/websocket.c
View file @
e84d0574
...
...
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "mongoose.h"
static
int
event_handler
(
struct
mg_event
*
event
)
{
...
...
@@ -25,14 +26,16 @@ static int event_handler(struct mg_event *event) {
mg_websocket_write
(
event
->
conn
,
WEBSOCKET_OPCODE_TEXT
,
server_ready_message
,
strlen
(
server_ready_message
));
// Read messages sent by client. Echo them back.
while
((
len
=
mg_websocket_read
(
event
->
conn
,
&
bits
,
&
data
))
>
0
)
{
// Echo message back to the client
mg_websocket_write
(
event
->
conn
,
WEBSOCKET_OPCODE_TEXT
,
data
,
len
);
printf
(
"got message: [%.*s]
\n
"
,
len
,
data
);
mg_websocket_write
(
event
->
conn
,
WEBSOCKET_OPCODE_TEXT
,
data
,
len
);
free
(
data
);
// It's our responsibility to free allocated message
// If the message is "exit", close the connection, exit the loop
if
(
memcmp
(
data
,
"exit"
,
4
)
==
0
)
{
mg_websocket_write
(
event
->
conn
,
WEBSOCKET_OPCODE_CONNECTION_CLOSE
,
""
,
0
);
free
(
data
);
break
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment