开发者

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? 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. it is listeing to a port 5000 and also i have my ip address. 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 ...


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. The Flash player supports a separate XMLSocket protocol, which you can also use if the Flash plugin is available. However, neither of these protocols supports raw access to sockets -- both require some initial negotiation and packet framing.


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. However, there are various ways to get around this restriction. Alex Sexton has a lengthy overview of all the different ways of doing this. However, all of those ways require that your socket program be running the http protocol also.

Socket.IO seems like a perfect fit for what you are trying to do, but you'll probably need to ditch your C program.


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. You could then use java script to pass the data to the app which would connect and forward it to the server.

Alternatively you could use some server side code and AJAX to proxy the connection and forward the data. 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.


I guess making one ajax request to required port on a server... can solve the request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜