Javascript将数据发送到端口 [英] Javascript send data to port

查看:87
本文介绍了Javascript将数据发送到端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,



我想问一下如何使用javascript将数据发送到特定端口(如1273)?



我的项目是google chrome的扩展,它应该用javascript编写,它应该能够将数据发送到端口,就像我上面提到的那样。

Hey,

I want to ask how i could send data to a specific port (like 1273) with javascript?

My project is an extension for google chrome which should be written in javascript and it should be able to send data to a port, like i've mentioned above.

推荐答案

用jQuery发送ajax请求。

jQuery.get(http:// localhost:25644,{},function(data){...做点什么},'json');

不要忘记处理错误(客户端没有响应时出现套接字错误)。
send ajax request with jQuery for example.
jQuery.get( "http://localhost:25644", {}, function(data){ ... do something },'json');
don't forget to handle error (socket errors when the client is not responding).


如果浏览器支持html5你可以使用WebSockets,谷歌获取更多信息和示例。
If the browser supports html5 you can use WebSockets, google for more info and examples.


这篇关于Javascript将数据发送到端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆