Reputation: 101
I also posted this in the Arduino section, but this problem is probably caused more by my ignorance of nanomsg and connections in general rather than an Arduino problem.
I am attempting to communicate with a server that is using nanomsg to communicate via TCP on a port using an Arduino. I have attempted a variety of different configurations (remotely connecting to the arduino and having the arduino connect to the server, using different nanomsg tools).
I can get the Arduino, in server mode (running a very slightly modified version of the WiFiWebServer example) to successfully read text I send using cat
sudo cat texttosend > /dev/tcp/192.168.1.50/80
However in all the configurations, and no matter what text I am trying to send using nanomsg, I always get a string of the same numbers. Printing the bytes as hex from the arduino, they are 0 53 50 0 0 51 0 0. Nanocat (the simple command line tool of nanomsg) hangs instead of sending and shutting down (like it is constantly trying to confirm the connection before sending the data).
I'm assuming this is some kind of handshake the Arduino is failing, because the client connects, reads those bytes, then shuts down and restarts. Using nanomsg on both ends (from my local computer to the server) works fine.
If these numbers I'm getting are a handshake, how do I complete it?
The meat of the loop part of the Arduino code is
client = server.available();
if (client) {
Serial.println("new client");
while (client.connected()) {
while (client.available()) {
byte b = client.read();
Serial.print(b,HEX);
Serial.write(b);
}
}
}
And the nanocat command that hangs when trying to connect is
nanocat --push --connect tcp://192.168.1.50:80 --data thismesadsfsdfg
Upvotes: 3
Views: 1126
Reputation: 1718
The following text describes nanomsg protocol for TCP.
In it you can see why you're getting the specified byte stream and what you should write before the text you want to send.
Upvotes: 2