nodejs net模块实现socket
2015-11-29 12:33
706 查看
var net = require('net'); var client = net.connect({port: 8080}, function() { console.log('连接到服务器!'); }); client.on('data', function(data) { console.log(data.toString()); client.end(); }); client.on('end', function() { console.log('断开与服务器的连接'); });
客户端代码
var net = require('net'); var server = net.createServer(function(connection) { console.log('client connected'); connection.on('end', function() { console.log('客户端关闭连接'); }); connection.write('Hello World!\r\n'); connection.pipe(connection); }); server.listen(8080, function() { console.log('server is listening'); });
服务器端代码
实现socket
相关文章推荐
- nodeJs常用的一些地址
- [Nodejs入门]第四篇,用nodejs实现一个爬虫的功能
- [nodejs入门]第一篇,javascript基础(2)
- node.js和socket.io纯js实现的即时通讯实例分享
- 237. Delete Node in a Linked List
- Swap Nodes in Pairs
- ROS_hydro_catkin建立标准程序包_helloworld.h+helloworld.cpp+helloworldnode.cpp
- NodeManagerMetrics上精确化Container指标监控
- NodeJS中使用benchmark进行基准测试-@alsotang
- nodejs学习--子进程 child_process模块的基本介绍
- nodejs学习--util
- nodej-- Query String
- A new node couldn't be inserted because one with the same name exists. (VERR_CFGM_NODE_EXISTS)
- nodejs学习--path
- [转][自己打脸]Node.JS——NodeJS引用路径的小问题
- nodejs-url
- nodejs学习1---基础知识
- node 可视化调试(支持监控文件变化)
- nodejs 快速实现url图片重定向
- java.lang.IllegalArgumentException: node to traverse cannot be null!