te')); return $arr; } /* 遍历用户所有主题 * @param $uid 用户ID * @param int $page 页数 * @param int $pagesize 每页记录条数 * @param bool $desc 排序方式 TRUE降序 FALSE升序 * @param string $key 返回的数组用那一列的值作为 key * @param array $col 查询哪些列 */ function thread_tid_find_by_uid($uid, $page = 1, $pagesize = 1000, $desc = TRUE, $key = 'tid', $col = array()) { if (empty($uid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('uid' => $uid), array('tid' => $orderby), $page, $pagesize, $key, $col); return $arr; } // 遍历栏目下tid 支持数组 $fid = array(1,2,3) function thread_tid_find_by_fid($fid, $page = 1, $pagesize = 1000, $desc = TRUE) { if (empty($fid)) return array(); $orderby = TRUE == $desc ? -1 : 1; $arr = thread_tid__find($cond = array('fid' => $fid), array('tid' => $orderby), $page, $pagesize, 'tid', array('tid', 'verify_date')); return $arr; } function thread_tid_delete($tid) { if (empty($tid)) return FALSE; $r = thread_tid__delete(array('tid' => $tid)); return $r; } function thread_tid_count() { $n = thread_tid__count(); return $n; } // 统计用户主题数 大数量下严谨使用非主键统计 function thread_uid_count($uid) { $n = thread_tid__count(array('uid' => $uid)); return $n; } // 统计栏目主题数 大数量下严谨使用非主键统计 function thread_fid_count($fid) { $n = thread_tid__count(array('fid' => $fid)); return $n; } ?>javascript - How to debug Node.js with Socket.io - Stack Overflow
最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to debug Node.js with Socket.io - Stack Overflow

programmeradmin3浏览0评论

I'm using the Google Chrome Developer Tools plugin for Eclipse to debug my Node.js server. This server uses Socket.io for the websocket connection between my web client and the server. The problem es when I set a breakpoint in my server and start stepping through the code. The client soon decides the server isn't there anymore because there's no longer a heartbeat or any munication, so it disconnects. Meanwhile, as I'm stepping through, my code tries to do something with the socket and then it dies since the socket is now shutdown. It makes it a bit tricky trying to debug like this.

So the question is, how can I debug a server like this with an open websocket connection and not close the connection? I don't know that there's a good solution, but I thought I'd put it out there and see if anyone has a genius idea.

I'm using the Google Chrome Developer Tools plugin for Eclipse to debug my Node.js server. This server uses Socket.io for the websocket connection between my web client and the server. The problem es when I set a breakpoint in my server and start stepping through the code. The client soon decides the server isn't there anymore because there's no longer a heartbeat or any munication, so it disconnects. Meanwhile, as I'm stepping through, my code tries to do something with the socket and then it dies since the socket is now shutdown. It makes it a bit tricky trying to debug like this.

So the question is, how can I debug a server like this with an open websocket connection and not close the connection? I don't know that there's a good solution, but I thought I'd put it out there and see if anyone has a genius idea.

Share Improve this question asked Oct 11, 2012 at 20:00 Justin WarkentinJustin Warkentin 10.2k4 gold badges37 silver badges35 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 7

After doing more research I discovered a couple different projects that looked hopeful, namely 'node-inspector' and 'node-codein'. However, node-inspector doesn't work with the latest versions of node, and node-codein has a lot of bugs. Also, neither is really maintained and they both only work with Chrome. So, I wrote my own solution, called Node Monkey, which is really simple to use and it works with Firefox or Chrome. It simply captures things logged to the console in your Node app and redirects that output to the browser console. You can install it by running:

npm install node-monkey

Even if it sounds a littly nasty and stone-aged, but in this cases (actually debugging a client->server environment) I regulary use standard outputs on the server-side, just like console.log() and console.debug.

If you need to debug your client-side script, you could do just the same, if you don't want to lose the server connection. I actually don't see any other way around it beside you re-configure socket.IO's heartbeat timeouts fundamentally higher.

I know this is ages later, but another option I found that ended up being perfect for a quick socket.io sanity check is socket-io-tester.

I mention it here since this answer was the first result on google and it took me a little more digging to find the tool.

for this you can follow official documentation of socket.io

https://socket.io/docs/v3/logging-and-debugging/index.html

In my case, I did this in my package.json

"scripts": {
 "test": "echo \"Error: no test specified\" && exit 1",
 "start": "DEBUG=engine,socket.io* nodemon src/server.js"},

I hope it will help you or feel free to ask me in case you have any doubt

发布评论

评论列表(0)

  1. 暂无评论