From ae6ee409b1c439c966436ddf780e793dddca9ff3 Mon Sep 17 00:00:00 2001 From: "sliver.chen" Date: Mon, 25 Dec 2017 20:14:13 +0800 Subject: [PATCH] [example]: check the return params to determine if the connection was successful when node.js server is not listening the port, connect will failed and return a null pointer,Then segment fault will occur if you continue to run it.So we should exit to avoid this error. Signed-off-by: sliver.chen --- src/examples/main.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/examples/main.cpp b/src/examples/main.cpp index 2555376..55082cc 100644 --- a/src/examples/main.cpp +++ b/src/examples/main.cpp @@ -74,6 +74,10 @@ int main(int argc, char* argv[]) //Establish the socket.io connection //JS: var socket = io.connect("localhost:3000") SIOClient *sio = SIOClient::connect("http://localhost:3000"); + if (sio == NULL) { + logger->information("Socket.io client connect failed sio:%p\n", sio); + return -1; + } //Create a target and register object its method onUpdate for the Update event //JS: socket.on("Update", function(data) {...});