简体   繁体   English

如何将数据从网页发送到 web 服务器的端口?

[英]how do i send data from a webpage to port in web server?

which is the best method to send a numerical value data from a javscript webpage to a web server port.. i have a server socket program running on the server and listening to port 5000. i need to send data from a webpage to the port?这是将数值数据从 javscript 网页发送到 web 服务器端口的最佳方法。我有一个服务器套接字程序在服务器上运行并监听端口 5000。我需要将数据从网页发送到端口? which is the best method?哪个是最好的方法?

the scene is this.场景是这样的。

i have a C socket program running at a web server hosted in my laptop using XAMPP.我有一个 C 套接字程序在使用 XAMPP 托管在我的笔记本电脑中的 web 服务器上运行。 it is listeing to a port 5000 and also i have my ip address.它正在监听端口 5000,而且我还有我的 ip 地址。 in the web page, i am running a javascript and when the user presses any of the arrow keys i need a value to be sent to this port.. like up -1, down -2 etc...在 web 页面中,我正在运行 javascript 并且当用户按下任何箭头键时,我需要将一个值发送到该端口。例如向上 -1、向下 -2 等...

There isn't currently any way to do this in a portable fashion.目前没有任何方法可以以便携式方式执行此操作。 Some browsers support the WebSocket standard , which gives you some limited access to sockets, but this isn't currently available in any common browsers other than Chrome and Safari.某些浏览器支持WebSocket 标准,这使您可以有限地访问 sockets,但目前在除 Chrome 和 Safari 之外的任何常见浏览器中均不可用。 The Flash player supports a separate XMLSocket protocol, which you can also use if the Flash plugin is available. Flash 播放器支持单独的XMLSocket协议,如果 Flash 插件可用,您也可以使用该协议。 However, neither of these protocols supports raw access to sockets -- both require some initial negotiation and packet framing.但是,这些协议都不支持对 sockets 的原始访问——两者都需要一些初始协商和数据包成帧。

Because your web server is running on a different port than your socket program, the Javascript in the browser is restricted from making requests directly to the socket program because of the Same Origin Policy .由于您的 web 服务器运行在与您的套接字程序不同的端口上,因此浏览器中的 Javascript 由于相同的来源策略而被限制直接向套接字程序发出请求。 However, there are various ways to get around this restriction.但是,有多种方法可以绕过此限制。 Alex Sexton has a lengthy overview of all the different ways of doing this.亚历克斯·塞克斯顿(Alex Sexton)对执行此操作的所有不同方式进行了冗长的概述 However, all of those ways require that your socket program be running the http protocol also.但是,所有这些方法都要求您的套接字程序也运行 http 协议。

Socket.IO seems like a perfect fit for what you are trying to do, but you'll probably need to ditch your C program. Socket.IO似乎非常适合您尝试做的事情,但您可能需要放弃您的 C 程序。

I guess making one ajax request to required port on a server... can solve the request.我想向服务器上的所需端口发出一个 ajax 请求......可以解决该请求。

The only way to open a network socket connection from a web page is to use a Java or Flash app to make the binary socket connection.从 web 页面打开网络套接字连接的唯一方法是使用 Java 或 Flash 应用程序进行二进制套接字连接。 You could then use java script to pass the data to the app which would connect and forward it to the server.然后,您可以使用 java 脚本将数据传递给应用程序,该应用程序将连接并将其转发到服务器。

Alternatively you could use some server side code and AJAX to proxy the connection and forward the data.或者,您可以使用一些服务器端代码和 AJAX 来代理连接并转发数据。 The second option doesn't rely on any browser plug-in being installed and I think would be easier to implement.第二个选项不依赖于安装任何浏览器插件,我认为会更容易实现。 It would also be able to forward to a port that is not on the web server itself as it wouldn't be subject to browser security restrictions.它还能够转发到不在 web 服务器本身上的端口,因为它不受浏览器安全限制。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何录制声音并将其从 web 应用程序发送到服务器? - How do I record sound and send it to a server from a web application? 如何将数据从Web发送到Linux服务器 - How to send data from web to linux server 如何从网页上的json数据创建对象? - How do I create objects from json data on a webpage? 如何通过网络服务器发送用于商业应用程序的数据? - How can I send data over a web server for a commercial application? 如何从android发送多部分/表单数据到Web服务器? - How to send multipart/form data to web server from android? 如何从Android将JSON数据发送到服务器WEB API - How to send json data to server WEB API from android 如何使客户端服务器Java应用程序在一个端口上发送消息,而在另一个端口上接收消息? - How do I make a client-server Java application to send messages on one port but receive them on another? 如何进行Socket连接并将数据从Android Wear发送到服务器 - How to do Socket connection and send data to server from Android Wear 如何通过短信将网页中的数据发送到移动设备 - how to send data from webpage to mobile device via SMS 如何将端口从台式机中的服务器发送到客户端中的客户端? - How to send port from server in desktop to client in client?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM