• Client API
  • How to connect an application to Lightstreamer server

Hi,
I'm new at Lightstreamer server and I'm trying to connect my application in Java with Lightstreamer. I've tried this https://github.com/Weswit/Lightstreamer-lib-node-adapterand when I'm running node adapters.js it says that localhost(I replaced LIGHTSTREAMER_SERVER_HOST with localhost) is not found
That is this code:
  1. Get the net package and create the connections to Lightstreamer server. Note that the ports are the same used in the above file; LIGHTSTREAMER_SERVER_HOST is the host of the Lightstreamer server e.g.: "localhost".

    varnet = require('net'),reqRespStream =net.createConnection(8001 , LIGHTSTREAMER_SERVER_HOST),notifyStream =net.createConnection(8002 , LIGHTSTREAMER_SERVER_HOST),metadataStream =net.createConnection(8003 , LIGHTSTREAMER_SERVER_HOST);
can anyone help me?
thanks
Hi Adriana,

First of all you should verify if the server is correctly configured, in particular see point 4 of section "Configure Lightstreamer", and if it is properly running: so, take a look at the log files in Lightstreamer/logs, and see if there are errors or warnings reported.
If server side everything seems working properly, but the Node Adapter still doesn't connect to the server, send us the exact error message you see.

HTH
Marco
Hi Marco,
I see the log file and there are no errors, the Lightstreamer is starting correctly.
This is the error message that the Node Adapter is giving to me when I call this command $ node adapters.js:

C:\Lightstreamer\adapters\NodeAdapter\lib\adapters.js:6
reqRespStream = net.createConnection(8001, localhost),
^
ReferenceError: localhost is not defined
at Object.<anonymous> (C:\Lightstreamer\adapters\NodeAdapter\lib\adapters.js:6:44)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3
Hi Adriana,

actually, if it's a literal string, you should write the address between quotes: so "localhost" instead of localhost, otherwise it is interpreted as a variable.
Thanks Marco, it passed but now it's giving me another error

module.js:340
throw err;
^
Error: Cannot find module 'lightstreamer-adapter'
at Function.Module._resolveFilename (module.js:338:15)
at Function.Module._load (module.js:280:25)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (C:\Lightstreamer\adapters\NodeAdapter\lib\adapters.js:11:24)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)

what I suppose do to?
I've installed Node.js manually, not by running these command npm install lightstreamer-adapter, because it gives me the following error:


/cygdrive/c/Program Files/nodejs/npm: line 2: $'\r': command not found
/cygdrive/c/Program Files/nodejs/npm: line 4: $'\r': command not found
/cygdrive/c/Program Files/nodejs/npm: line 5: syntax error near unexpected token `$'in\r''
'cygdrive/c/Program Files/nodejs/npm: line 5: `case `uname` in
Hi Adriana,

if you have installed the windows version of node.js, try to run 'npm install lightstreamer-adapter' from a windows command instead of from a cygwin shell.
Hey Marco you were right, the installation passed that way, but running node adapters.js gives the same error... :/

Any idea what should I do?
if the error is still "Error: Cannot find module 'lightstreamer-adapter'", it means it is not able to properly install the adapter.
try to uninstall the adapter, clear the cache and reinstall it.

npm uninstall lightstreamer-adapter
npm cache clean
npm install lightstreamer-adapter

hth
Thanks Marco, it helps, but now I have another error

dataProvider.update(itemName, false, {
^
ReferenceError: itemName is not defined
at Object.<anonymous> (C:\Lightstreamer\sdk_adapter_node_1.0.0_build_3\lib\node_modules\lightstreamer-adapter\lib\adapters.js:33:21)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:901:3

for what stands itemName, what is for?

tnx
As before itemName should be a literal string, so somethink like "MyItemName", or a variable: in this case you should have done before something like:
var itenName = "MyItemName"
You were right :Smile_Ab:
Could you tell me what are these fields for
'field1': valField1,
'field2': valField2 ?
You were right :Smile_Ab:
But now it says fields are not defined.
'field1': valField1, 'field2': valField2
for what are these?