gRPC C++ Error code 14 : failed to connect to all addresses - c++

I am trying to implement gRPC server/ client for the first time using Windows Subsystem for Linux kernel and CLion as the IDE (on Windows). My code does not have any other bugs/ issues except this communication failure.
The following lines of code
if(status.ok()) {
cv::imshow("Rotated image", decrypt_img);
} else {
std::cout << status.error_code() << " : " << status.error_message() << std::endl;
}
yields the following message
14 : failed to connect to all addresses

This is a kind of generic error message from grpc which can have multiple causes.
In my experience, it can be one of the following things:
Your server isn't running (either you forgot to call grpc::ServerBuilder::BuildAndStart or you didn't start your server application all along).
When running the server for the first time Windows Firewall should ask you if you want to allow your application to access the network (I don't recall the actual wording). You want to accept this, of course.
You have a wrong address specified in your client application (i.e. a different one than you have set in your server application via grpc::ServerBuilder::AddListeningPort)
Not knowing your actual server and client code these are just assumptions I can make based on my experience with grpc.

Related

Connect to multiple queue managers in different servers

I am trying to connect a C++ application (using MQCONNX) based on a PaaS IBM MQ client to two different queue managers, each one based on a different server (one in a PaaS server and the other one in a Unix server). Unfortunately I am not able to do it as I am getting a message when I try to connect to the second server saying that it is not possible as it is connected to the first queue manager. I am using two different MQHCONN connections, one for each queue manager, but the problem is still there.
I have taken a look into this link, but I still have some doubts, as for example, from which server should I copy the CCDT to the client?
https://www.ibm.com/support/pages/connecting-mq-clients-multiple-queue-managers-client-channel-definition-table-ccdt
Any help would be much appreciated, or even a quick sample of how to use CCDT, as right now I am completely stuck.
Many thanks in advance for any help.
Assuming Queue Manager 1 is called MQG1 and Queue Manager 2 is called MQG2 and these can be found using connection names of machine1.com(1701) and machine2.com(1702) respectively, and using channel names MQG1.SVRCONN and MQG2.SVRCONN respectively, you can create your CCDT, on your client application machine, thus:-
runmqsc -n
issue these commands into runmqsc:-
DEFINE CHANNEL(MQG1.SVRCONN) CHLTYPE(CLNTCONN) CONNAME('machine1.com(1701)') QMNAME(MQG1)
DEFINE CHANNEL(MQG2.SVRCONN) CHLTYPE(CLNTCONN) CONNAME('machine2.com(1702)') QMNAME(MQG2)
Then you can code your 2 x MQCONN (or MQCONNX if you need to specify any additional things on the connection) thus:-
#include <cmqc.h> /* Includes for MQI constants */
#include <cmqstrc.h> /* Convert MQRC into string */
MQHCONN hConn1 = MQHC_UNUSABLE_HCONN;
MQHCONN hConn2 = MQHC_UNUSABLE_HCONN;
MQCHAR QMName1[MQ_Q_MGR_NAME_LENGTH] = "MQG1";
MQCHAR QMName2[MQ_Q_MGR_NAME_LENGTH] = "MQG2";
MQLONG CompCode, Reason;
MQCONN(QMName1,
&hConn1,
&CompCode,
&Reason);
if (CompCode)
{
printf("MQCONN to %s failed with reason code %s (%d)\n", QMName1, MQRC_STR(Reason), Reason);
}
MQCONN(QMName2,
&hConn2,
&CompCode,
&Reason);
if (CompCode)
{
printf("MQCONN to %s failed with reason code %s (%d)\n", QMName2, MQRC_STR(Reason), Reason);
}
Take care with how you are linking your program. If you try to make two local connections, you will get a return code of MQRC_ANOTHER_Q_MGR_CONNECTED. Ensure you either link with the client library, set connection option MQCNO_CLIENT (which means you must use MQCONNX) or set the environment variable MQ_CONNECT_TYPE=CLIENT.
You might find the following blog post useful additional reading:-
IBM MQ Little Gem #30: MQ_CONNECT_TYPE

Apache Thrift timeout

I'm using apache thrift in version 0.13.0.
As soon as the time between two calls is approximately 1.5 seconds the connection will be closed.
The timeout varies from 1.3 to 1.8 seconds.
keepAlive is set in server and client. I tried different for rx, tx but this did not change anything.
My client code used for testing is below.
The client is using windows and the server is running linux.
for (int i = 0; i < 100'000;i+=50){
remote_method();
auto sleep = std::chrono::milliseconds(i);
std::cout << "Sleep: " << i << "\n";
std::this_thread::sleep_for(sleep);
}
Thrift will throw an exception in the code snippet below, which is located in TSocket.cpp
// Timed out!
if (errno_copy == THRIFT_ETIMEDOUT) {
throw TTransportException(TTransportException::TIMED_OUT, "THRIFT_ETIMEDOUT");
}
It looks like something is resetting the connection after this time.
If the method is called with a high frequency no timeout occurs.
Thrift is working correctly, other socket based communication is showing this behavior as well. The root cause was the VMware virtual machine the server was running in. The network mode (briged, NAT, or host only) did not make a difference. By moving the server to a physical machine the problem has been solved. Most likely the network configuration of the linux is faulty.

ACE with multiple app instances on same pc - only first gets the message

I'm trying to create application where multiple instances will run on same machine and they will communicate together via UDP via the same port.
I was reading many threads on StackOverflow about it that it should be possible.
Though, when I open connection from each application instance I can see that each instance sends a message but only first instance (if first is closed then second...) receives that message.
I'm using ACE library for the communication. Excerpt from code:
ACE_SOCK_Dgram_Mcast dgram;
ACE_INET_Addr *listenAddress = new ACE_INET_Addr(12345, ACE_LOCALHOST);
dgram.open(*listenAddress);
ACE_INET_Addr peer_address;
char buffer[1024];
dgram.send(buffer, 256);
while (true)
{
if (dgram.recv(buffer, 256, peer_address, 0, &receiveLoopTimeout) != -1)
{
std::cout << "Received" << std::endl;
}
}
I also found out that if I call "dgram.join(*listenAddress)" then I get error, code ENODEV from the first instance of the app.
I'm not sure I understand what you are trying to do... send a message multicast so multiple receivers get it, or allow multiple processes to receive on the same UDP port unicast... I'm guessing the former.
You're using the ACE_SOCK_Dgram_Mcast class but with unicast addressing and operations. So only one instance will receive that message.
Check the ACE_wrappers/tests/Multicast_Test.cpp for examples of how to send and receive multicast.

Trying to change realtime clock in Ubuntu 14.04 in C++ application, getting "Operation not permitted"

OS: Ubuntu
Version: 14.04
Language: C++11
I've written an application that needs to change the real-time clock based on different sources. As background, the reason that I'm not using NTP to manage this is based on different clock sources that are needed at different points, for all the current applications using CLOCK_REALTIME. This application receives a clock reference time and sets the clock using clock_settime. This returns the message Operation not permitted.
if(clock_settime(CLOCK_REALTIME, &timeRT) != 0)
{
std::cerr << " Set clock_settime(CLOCK_REALTIME, &timeRT) = " << strerror(errno) << std::endl;
}
I presume the applications privileges are not set correctly.
Any direction on how to do this?
Anything else I should check?
Run your application as root, and before trying to set the clock, call:
procmgr_ability( 0, PROCMGR_AID_CLOCKSET );
You will need to include:
#include <sys/procmgr.h>

Libnodave - daveStart() Error using TCP Connection

I have established connection to a Siemens S7-300 PLC (simulated via PlcSIM) using the libnodave library. There are no issues connecting and writing data to the PLC. However, I am unable to change the status of the PLC from Start/Stop. I am attempting to use the following libnodave methods for such actions:
int daveStatus = daveStart(dc);
int daveStatus = daveStop(dc);
Both function calls return the same Error: 33794
nodave.c Cites the error as the following:
case 0x8402: return "CPU already in RUN or already in STOP ?";
The use of the daveStart() and daveStop() functions can be viewed in the example testS7online.c:
if(doStop) {
daveStop(dc);
}
if(doRun) {
daveStart(dc);
}
In the examples the start/stop functions are only called when MPI connections to the PLC are made. Does anyone know if the start/stop functions are supported for use with TCP connections? If so, any suggestions as to what may be causing my error?
I have just tried dc.start() and dc.stop() using libnodave 8.4 and NetToPlcSim tool. It worked perfectly. Possibly you don't use NetToPlcSim tool that makes connection to PLCSim via TCP/IP (that is 127.0.0.1 port 102 obviously) hence dc can't even connect. So if your lines don't work, then u must be doing something wrong.