0

我正在用 pusher 实现套接字编程。但我不知道在哪里写 ip 地址,以便我可以从服务器获取数据。我正在使用这个例子 https://github.com/pusher/pusher-phonegap-android 你能告诉我我在哪里写 Ip s 我会得到回应。(函数($){

  var CONFIG = {
    PUSHER: {
      APP_KEY: '49e26cb8e9dde3dfc009'
    }
  };

  Pusher.log = function(msg) {
    if (window.console && window.console.log) {
      window.console.log(msg);
      $( '#debug_log' ).prepend( msg );
    }
  };

  document.addEventListener("deviceready", onDeviceReady, false);

  function onDeviceReady() {

    // Get device info
    var deviceInfo = 'Device Name: ' + device.name + '<br />' +
      'Device Cordova: ' + device.cordova + '<br />' +
      'Device Platform: ' + device.platform + '<br />' +
      'Device UUID: ' + device.uuid + '<br />' +
      'Device Version: ' + device.version + '<br />';

    $('#deviceProperties').html(deviceInfo)

    // Connect
    var pusher = new Pusher("ws://192.168.1.3:8101/");// i am writting Here my ip but connection problem occur
    pusher.connection.bind('state_change', connectionStateChange);

    function connectionStateChange(state) {
      $('#connectionStatus').html(state.current);
    }

    // Subscribe
    var channel = pusher.subscribe('my-channel');
    channel.bind('pusher:subscription_succeeded', subscriptionSucceeded);

    function subscriptionSucceeded() {
      $('#subscriptionStatus').html('succeeded');
    }

    channel.bind('my-event', handleMyEvent);

    function handleMyEvent(data) {
      $('#debug_log').append('<pre>' + JSON.stringify(data, null, 2) + '</pre>');
    }

  }

})(jQuery); 
4

1 回答 1

0

来自我这边的愚蠢问题,实际上是否有 websocket 服务器在指定主机上监听?

更新: Pusher 是托管平台,所以你不能在本地运行它。如果您愿意,可以使用像 Slanger( https://github.com/stevegraham/slanger )这样的开源替代品。请参阅它的文档,其中描述了如何相应地设置 Pusher 客户端。

于 2013-07-03T09:16:46.253 回答