Read multiple responses from TCP Socket - node.js

I am trying to query an INSTEON home automation server using a js net socket.
When I connect interactively and send a status query via the console I get two packets back:
Connected to: xxx.xxx.xxx.xxx:9761
02621FE3E80f1900 <-- typed into console
Send: 02621FE3E80f1900
Rsvd: 02621fe3e80f190006
Rsvd: 02501fe3e81ec00a2f0000
quit <-- typed into console
Connection closed
The second one arrives about half a second after the first.
However, when I try to send the message inside the js script, using: client.write('02621FE3E80f1900','hex'); I only get the first message back:
Connected to: xxx.xxx.xxx.xxx:9761
Rsvd: 02621fe3e80f190006
Connection closed
How can I get access to both messages?
I need the first message to confirm my query was received successfully,
and the second message in a string so I can interrogate it...
John

Related

Send MQTT message from the android client to all the clients through MQTT broker

I need MQTT broker to publish the received MQTT message from the Android client to all other clients so added mosquitto pub command in the body of the message.
publish(client,"mosquitto_pub -h 192.34.63.138 -t fromApp -m "Turn" -d ");
It is giving error that "Can't resolve symbol "Turn" and ; or ) expected" .
Update
I understood it correctly later. I actually needed an MQTT message from the android client to be sent to all other clients so I thought to include publish keyword in the message body which was quite wrong. The MQTT itself sends the received messages to all the clients provided if the clients have subscribed to that topic.Hopefully, it will help other readers.
There are a number of problems with your approach.
First, the compile time error is because you have nested " within a String (which is bound by ". To do this you need to escape the "'s with the \ as follows:
"mosquitto_pub -h 192.34.63.138 -t fromApp -m \"Turn\" -d "
The second problem is the more important one. MQTT doesn't work the way you seem to be expecting it to.
You do not send commands to the broker for it to execute, you publish a message from one client to a topic, and the broker then delivers that message to all the clients that have subscribed to that topic. So in this case you would just publish a message with the payload Turn to the topic fromApp. Which is going to look something like:
MqttMessage message = new MqttMessage("Turn".getBytes());
sampleClient.publish("fromApp", message);

How do I roll-back a message to Amazon MQ (AMQ) from Lambda?

So, I assume this relates to any Node.js and Active MQ installation but I am using Amazon MQ with Node.js Lambda...
Kind of a noob on ActiveMQ so please correct me where I am wrong!
After reading a message from a queue using stompit I continue processing the message and it shall then be sent over HTTPS to another server.
There is some message validation and enrichment happening on the way to the HTTPS POST, and of course the POST itself can result in an error.
How would I (best) handle a roll-back of the message in case of an error:
1) Keep the connection open and not send client.ack() until I finally got a HTTP 200 back from remote server?
2) Keep the message in a variable and put it back in case of error (sequence doesn't matter?
3) Use something other than stomp?
It is apparently not possible using STOMP so I've changed the code to use the library ampq10 instead.
import amqp10 from 'amqp10';
const AMQPClient = amqp10.Client;
const amqpClient = new AMQPClient({
receiverLink: {
attach: {
rcvSettleMode: amqp10.Constants.receiverSettleMode.settleOnDisposition
},
creditQuantum: 1
}
});
This will allow you to do a receiver.accept(message); if successfully handling the message. If you just .disconnect() whitout an .accept() the message will not be removed from the queue.

JMS Message body is null when publishing with jms:publish-subscribe-channel

I am trying to use jms:publish-subscribe-channel to pub/sub on a single ActiveMQ topic. I am able to receive messages from ActiveMQ on the channel just fine, however when I publish to the channel the message body is null (when received by another application listening on the ActiveMQ topic). I was able to recreate the problem using spring-integration-samples->basic->jms. I modified outboundChannelAdapter.xml to use jms:publish-subscribe-channel instead of jms:outbound-channel-adapter. Is there another step needed in order to publish a simple string message? Here's my code change to outboundChannelAdapter.xml:
<stream:stdin-channel-adapter id="stdin" channel="stdinToJmsoutChannel"/>
<jms:publish-subscribe-channel id="stdinToJmsoutChannel" topic="requestTopic" />
<stream:stdout-channel-adapter id="stdout" channel="stdinToJmsoutChannel" append-newline="true"/>
I am not sure what you mean by "the message body is null".
I just made the exact same change to the sample and it worked fine for me...
Please type something and hit <enter>
foo
foo
I had to add -Dorg.apache.activemq.SERIALIZABLE_PACKAGES=* to the command line because activemq needs whitelisting for classes (the whole message is serialized in jms-backed channels).

Passbook web services to update a pass

I have created a web service to update our passbooks with the following entries in my routes file:
// Registering a Device to Receive Push Notifications for a Pass
app.post('/Passbook/v1/devices/:dli/registrations/:typeid/:serial', PBAdmin.registerDevice);
// Getting the Serial Numbers for Passes Associated with a Device
app.get('/Passbook/v1/devices/:dli/registrations/:typeid',PBAdmin.getSerialNumbers);
// Getting the Latest Version of a Pass
app.get('/Passbook/v1/passes/:typeid/:serial', PBAdmin.getUpdatedPass);
// Unregistering a Device
app.delete('/Passbook/v1/devices/:dli/registrations/:typeid/:serial', PBAdmin.unregisterDevice);
// Logging Errors
app.post('/Passbook/v1/log', PBAdmin.logErrors);
The problem is that after a passbook is downloaded by a user my web service end point receives a GET request instead of POST request for registering a device (from my log file)
GET /Passbook/v1/devices/xxxxxxxxxxxxxxe99ddc69a5a9/registrations/xxx.xxxx.xxxx.app.dev.passbook/1408646948910 401 18ms - 12b
In fact this happens for the log handler as well (which is supposed to be POST with error message). I am not sure why that is and how to fix it.

Reason for Uncaught Error: Attempting to use a disconnected port object

I am getting this error in background page when responding to request
from content script.
Does anyone know what can be causing this error?
Full stack trace:
Uncaught Error: Attempting to use a disconnected port object chrome/RendererExtensionBindings:147
chrome.Port.postMessage chrome/RendererExtensionBindings:147
chromeHidden.Port.dispatchOnConnect.connectEvent chrome/RendererExtensionBindings:89
myExtension.foo.sendResponse.state background.js:1573
db.readTransaction.tx.executeSql.paramStr background.js:1038
This only happens after a couple of hours of browsing reloading extension is not helping - not that it would be a solution after restarting chrome browser all gets back to normal for couple of hours content script can keep sending request to background but NO response
from background can be sent back Is there any way I could catch this Uncaught error and reset the listener?
I am using chrome.extension.onRequest.addListener for my communication. Before I respond I query DB and I do not send any other response before query is finished.
Thanks,
Marek
This is caused when a connection get closed. For example if you open a tab that has the content_script injected, it opens a connection, the tab is closed, and then the background_page tries to pass a message. It will fail because the tab is no longer active to receive the message.
In your case I would guess that as tabs close and new tabs open you are attempting to post messages with the old tabId instead of creating a new connection to the new tab. I would recommend reading through the long-lived connections section again.
In my case, however, I needed to provide the sendResponse function to the chrome.runtime.sendMessage(msg, responseCallbackMissingHere), which will give you the "Attempting to use a disconnected port object" error.

Resources