doudou0111 2017-10-25 12:53 采纳率: 0%
浏览 69

如何从Web应用程序连接到原始TCP套接字服务器?

I have a web application hosted on AWS written in Laravel/PHP ; i need to let the web application to talk with a socket server listening on port 9090 in a server placed in the same internal network (not in AWS) of the browsers that use the webapp; the socket server DOES NOT support websocket but only raw sockets; how can the client connect to the socket server? Do i need to write client programs in python/other lang to be installed on client machines or is there a better way?

  • 写回答

3条回答 默认 最新

  • doufocheng6233 2017-10-25 12:58
    关注

    Yes, you need to write client program/script which would listen to the socket and using the script you can manipulate front-end pages.

    I would recommend Javascript code which would listen to your web socket at 9090 and based on the received data, you can make changes on the web page.

    Here is the sample code for your reference.

    <script src="http://localhost:8080/socket.io/socket.io.js"></script>
    <script>
        // Create SocketIO instance, connect
    
        var socket = new io.Socket();
    
        socket.connect('http://127.0.0.1:8080'); 
    
        // Add a connect listener
        socket.on('connect',function() {
          console.log('Client has connected to the server!');
        });
        // Add a connect listener
        socket.on('message',function(data) {
          console.log('Received a message from the server!',data);
          // This `data` can be used to show on the page or anything else.
        });
        // Add a disconnect listener
        socket.on('disconnect',function() {
          console.log('The client has disconnected!');
        });
    
        // Sends a message to the server via sockets
        function sendMessageToServer(message) {
          socket.send(message);
        };
    </script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办