Giter Site home page Giter Site logo

Comments (7)

bailicangdu avatar bailicangdu commented on April 28, 2024 4

nodejs是单线程的,准确说js是单线程的,它不会因为 I/O 操作而阻塞,一旦出现异步,就直接略过,放入事件循环同时注册一个回调,然后执行下面的语句,等异步执行完之后,调用回调,这时候nodejs再次处理这个已经处理好的异步。

from node-elm.

bailicangdu avatar bailicangdu commented on April 28, 2024

其实nodejs并不适合大型项目的开发,所有的请求都在一个线程里,一个人崩,所有人都崩。所以很少有大型的开源项目。至于文件之间的交互,都是require,export,当然es6的import export更好一点

from node-elm.

SSSANTON avatar SSSANTON commented on April 28, 2024

这样啊。
现在要做这样的一个东西:浏览器请求图片——HTTP SERVER——TCP SERVER——TCP SOCKET终端(多终端,TCP长连接)返回图片——TCPSERVER——HTTP SERVER——浏览器
就做获取图片列表和下载图片两个路由,node应该能胜任,就是不知道怎么tcp和http之间怎样交互。

from node-elm.

bailicangdu avatar bailicangdu commented on April 28, 2024

socket.io 可以将http协议,改为tcp协议,api简单强大

from node-elm.

SSSANTON avatar SSSANTON commented on April 28, 2024

在某个路由里实现如下逻辑:
router.post('/', urlencodedParser, function(req, res, next)
{
调用TCP服务器往TCP终端发送命令
获取到TCP终端返回的数据
把数据返回浏览器客户端
}

可以做到吗?

socket.on('data',function(data)
{
var str=data.toString();
}
主要是不会从这个异步事件返回数据到路由上

from node-elm.

bailicangdu avatar bailicangdu commented on April 28, 2024

事件是异步的,只需要在执行完I/O之后调用回调就行

from node-elm.

SSSANTON avatar SSSANTON commented on April 28, 2024

大神,能不能讲解清楚一点。最好有简单的代码说明~

from node-elm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.