3

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
Right leg
  • 16,080
  • 7
  • 48
  • 81
Eric D
  • 101
  • 1
  • 5
  • 1
    Have you tried adding `--format ascii` at you command? Or put you data in `" "`, such as `"message"`? – SSC Dec 21 '14 at 03:56
  • 1
    I have tried sending a variety of messages (quotes, no quotes, random strings, etc), but nothing changes what the Arduino receives. The formatting flag is only for receiving data, I don't have control over how nanocat sends the data (from what little I know anwyay). – Eric D Dec 21 '14 at 04:40
  • 1
    Turns out this is part of nanomsg. http://www.freelists.org/post/nanomsg/Status,242 – Eric D Dec 21 '14 at 23:51

1 Answers1

2

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.

sg7
  • 6,108
  • 2
  • 32
  • 40
nitzanms
  • 1,786
  • 12
  • 35