2017-10-08 124 views
0

我有一個feathersjs服務器正在運行,我可以從瀏覽器客戶端(使用webpack)成功連接到該服務器。現在我正嘗試從運行在Raspberry Pi3上的nodejs應用程序連接到同一臺服務器。當我查找時,我看不到服務器的活動。我爲該服務創建了一個鉤子記錄器,並且它什麼都不記錄。我只能假設客戶端從不連接。該服務沒有驗證鉤子,因爲我只是在開發中,所以不需要驗證模塊。Feathersjs節點套接字客戶端未連接

我可以從RPI ping服務器,如果我把服務器IP /端口插入到RPI上的瀏覽器中,我會得到我的「我是羽毛服務器使用客戶端」頁面,以便網絡連接和IP設置服務器很好。

任何關於如何追蹤發生的事情的幫助。沒有任何連接日誌(在客戶端上),我不知道發生了什麼。我得到的只是.catch的超時錯誤。

下面是我的客戶端代碼,來自工作瀏覽器客戶端的客戶端代碼。

工作的瀏覽器客戶端安裝

import feathers from 'feathers' 
import hooks from 'feathers-hooks' 
import socketio from 'feathers-socketio' 
import auth from 'feathers-authentication-client' 
import io from 'socket.io-client' 

// const socket = io('http://localhost:3030', {transports: ['websocket']}) 
// const socket = io('http://192.168.43.114:3030', {transports: ['websocket']}) 
const socket = io('http://192.168.0.51:3030', { transports: ['websocket'] }) 

const api = feathers() 
    .configure(hooks()) 
    .configure(socketio(socket)) 

// .configure(AUTH({存儲:window.localStorage}))

export default api 

不工作的NodeJS客戶端安裝

const feathers = require('feathers/client'); 
const socketio = require('feathers-socketio/client'); 
const hooks = require('feathers-hooks'); 
// const errors = require('feathers-errors'); // An object with all of the custom error types. 
// const auth = require('feathers-authentication-client'); 

const io = require('socket.io-client/dist/socket.io'); 

const socket = io('http://192.168.0.51:3030', { transports: ['websocket'] }) 

const feathersClient = feathers() 
    .configure(hooks()) 
    .configure(socketio(socket)) 
//.configure(auth()) 

module.exports = feathersClient; 

節點應用程序,它只是在我的服務上進行查找。

const api = require('./api') 

const switches = api.service('switches') 

switches.find({ 
    paginate: false 
}) 
    .then((response) => { 
     console.log('loading all switch data', response.data) 
    }) 
    .catch((err) => { 
     console.log('error loading switch data', err) 
    }) 

錯誤從.catch

error loading switch data Error: Timeout of 5000ms exceeded calling switches::find 
    at Timeout._onTimeout (/opt/lighting-dev/node_modules/feathers-socket-commons/lib/client.js:87:25) 
    at ontimeout (timers.js:469:11) 
    at tryOnTimeout (timers.js:304:5) 
    at Timer.listOnTimeout (timers.js:264:5) 

回答

0

原來的羽毛文檔的NPM /節點客戶端是不正確的。 https://docs.feathersjs.com/api/client.html

的要求

const io = require('socket.io-client/dist/socket.io'); 

是瀏覽器只

爲使用的NodeJS只是基礎客戶端

const io = require('socket.io-client); 

和它的作品。