Comments (7)
nodejs是单线程的,准确说js是单线程的,它不会因为 I/O 操作而阻塞,一旦出现异步,就直接略过,放入事件循环同时注册一个回调,然后执行下面的语句,等异步执行完之后,调用回调,这时候nodejs再次处理这个已经处理好的异步。
from node-elm.
其实nodejs并不适合大型项目的开发,所有的请求都在一个线程里,一个人崩,所有人都崩。所以很少有大型的开源项目。至于文件之间的交互,都是require,export,当然es6的import export更好一点
from node-elm.
这样啊。
现在要做这样的一个东西:浏览器请求图片——HTTP SERVER——TCP SERVER——TCP SOCKET终端(多终端,TCP长连接)返回图片——TCPSERVER——HTTP SERVER——浏览器
就做获取图片列表和下载图片两个路由,node应该能胜任,就是不知道怎么tcp和http之间怎样交互。
from node-elm.
socket.io 可以将http协议,改为tcp协议,api简单强大
from node-elm.
在某个路由里实现如下逻辑:
router.post('/', urlencodedParser, function(req, res, next)
{
调用TCP服务器往TCP终端发送命令
获取到TCP终端返回的数据
把数据返回浏览器客户端
}
可以做到吗?
socket.on('data',function(data)
{
var str=data.toString();
}
主要是不会从这个异步事件返回数据到路由上
from node-elm.
事件是异步的,只需要在执行完I/O之后调用回调就行
from node-elm.
大神,能不能讲解清楚一点。最好有简单的代码说明~
from node-elm.
Related Issues (20)
- 接口用不了了
- 如何修改地图类api接口为自己的腾讯地图接口 HOT 2
- 接口用不了了
- 你好,接口用不了了 HOT 1
- stack Error: Could not find any Python installation to use 报错 HOT 1
- 崩溃了
- node-elm HOT 1
- 用户名密码验证码 登入时出错
- 大佬 ,接口用不了了,可以修复一下吗 HOT 1
- 填写完用户名 密码 验证码 登陆失败,但是用postman测试就成功是为什么啊
- 项目启动时报mongodb错误,请问下是什么原因 HOT 3
- MongoDB配置简易教程 HOT 1
- elm的搜索餐馆接口出了问题
- elm的搜索地址接口出了问题 HOT 3
- 接口挂了,是服务器崩了吗,该咋办啊
- 关于接口报错的解决办法
- bailicandu /
- 接口蹦了,能整一下吗亲!
- 后端程序报错,接口504 HOT 1
- 搜索地址接口出问题了,能不能修复一下 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-elm.