最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to send udp to udp node.js server? - Stack Overflow

programmeradmin3浏览0评论

I'm very new to this so I really don't know what I'm doing, but I've setup a node.js udp server. I want to send a packet to it from the client (being from a website), but I don't know how to do that in javascript/ or if it's even possible. I'm not looking on how to send a packet from a node.js client to server, but rather how to write a website to send a packet to a node.js udp server. Not sure if that made sense, but thanks for the help!

I'm very new to this so I really don't know what I'm doing, but I've setup a node.js udp server. I want to send a packet to it from the client (being from a website), but I don't know how to do that in javascript/ or if it's even possible. I'm not looking on how to send a packet from a node.js client to server, but rather how to write a website to send a packet to a node.js udp server. Not sure if that made sense, but thanks for the help!

Share Improve this question asked Sep 17, 2011 at 0:04 DerekDerek 12.4k31 gold badges106 silver badges166 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

You may be interested in this tutorial:

http://fzysqr./2011/02/28/nodechat-js-using-node-js-backbone-js-socket-io-and-redis-to-make-a-real-time-chat-app/

It goes through how to create a chat application in node.js in very fine detail, he even shows how to use Socket.io (a browser js library) to utilize web sockets for realtime, low latency responses.

And as Phihag hinted at, UDP isn't good for this sort of application because UDP does not guarantee your packet will get to its destination. You definitely want to use TCP Sockets in this case.

More reading:

  • http://en.wikipedia/wiki/Transmission_Control_Protocol
  • http://en.wikipedia/wiki/User_Datagram_Protocol

You cannot send UDP datagrams from a webbrowser (i.e. JavaScript). What you can do is contact a webserver (for example via AJAX or websocket) and execute a server-side program (in php or node.js or so) to send the UDP datagram. You can send a UDP datagram with the server-side programming language's native socket module (Python, php, node.js).

However, why are you using UDP in the first place? You'll have to handle retransmissions, reordering and the like, and since webbrowsers can only talk via TCP, you're not getting any of the advantages of UDP.

发布评论

评论列表(0)

  1. 暂无评论