Java知识分享网 - 轻松学习从此开始!    

Java知识分享网

Java1234官方群25:java1234官方群17
Java1234官方群25:838462530
        
SpringBoot+SpringSecurity+Vue+ElementPlus权限系统实战课程 震撼发布        

最新Java全栈就业实战课程(免费)

springcloud分布式电商秒杀实战课程

IDEA永久激活

66套java实战课程无套路领取

锋哥开始收Java学员啦!

Python学习路线图

锋哥开始收Java学员啦!

Node-Cookbook-3rd PDF 下载


分享到:
时间:2023-09-05 11:11来源:http://www.java1234.com 作者:转载  侵权举报
Node-Cookbook-3rd
失效链接处理
Node-Cookbook-3rd  PDF 下载 



 
 
相关截图:
 
主要内容:

How it works...
Our server uses net.createServer to instantiate a TCP server.
This returns an object with a listen method which is called with two
arguments, 1337 and localhost, which instruct our server to listen on port 1337
on the local loop network interface.
The net.createServer method is passed a connection handler function, which is
called every time a new connection to the server is established.
This function receives a single argument--the socket.
We listen for a data event on the socket and then send the data back to the
client embedded inside a greeting message, by passing this greeting to the
socket.write method.
We also listen for a close event, which will detect when the client closes the
connection, and log a message if it does.
Our client uses the net.connect method, passing it the same port and hostname
as defined in our server, which in turn returns a socket.
We immediately write the name to the socket and attach a data listener in order
to receive a response from the server. When we get a response, we simply log
it to the terminal. We have to call the toString method on incoming data
because sockets deliver raw binary data in the form of Node buffers (this
string conversion happens implicitly on our server when we embed the buffer
into the greeting string).
Finally, our client also listens for a close event, which will trigger in cases
where the server ends the connection.

------分隔线----------------------------

锋哥公众号


锋哥微信


关注公众号
【Java资料站】
回复 666
获取 
66套java
从菜鸡到大神
项目实战课程

锋哥推荐