-2

I have a Linux Server running Redhat Rhel 7 and a Device called "Compoint Lan System (Colas)" (german manufacturer). The Colas has its own firmware so I don't know if it's based on linux. The Colas is set as a TCP-Client. It receives messages from its serial 1 port. I get the messages coming from the serial port 1 of the colas on my server with rsyslog.

Now what I want is to send a string (2 letters) from my server (tcp-server) to my colas's serial port 1 (tcp-client) to get information of the device attached to serial port 1.

Is there a command in linux to accomplish that? Something like "command 'string message' destination port"? I am sorry if it isn't written well.

SchnoppDog
  • 21
  • 6
  • 1
    Check netcat or telnet. Both of these tools can send raw TCP data. There may be other tools as well that can be used. Personally I would write a small python script for this as basic TCP handling can be done very quickly. For more information check [Python socket docs](https://docs.python.org/3/howto/sockets.html) – Jonaswg Feb 20 '19 at 11:46
  • Sounds like you want to write to a serial port, not a tcp port? Maybe check this out: https://stackoverflow.com/questions/8877269/writing-to-serial-port-from-linux-command-line – e.dan Feb 20 '19 at 11:47

2 Answers2

1

Install netcat

yum install nc

Make it to listen to a particular port number

nc –l portnumber &

Lets validate it using netstat from a different console:

netstat -anlp |grep yourportnumber

PS: Change the installation command based on your linux flavor.

Ranadip Dutta
  • 8,857
  • 3
  • 29
  • 45
  • That's not what i wanted. I don't want to listen to the incoming data of my colas-device I want to send two letters / characters to the from my server to the device. Imagined it in a different way: The device attached to the colas-device is sending special letters. I need to send a special string to this device to get the systemstatus of it. For example: I receive the letters "a" and "b" and I need to send the letter "c" in order to get system information from it – SchnoppDog Feb 20 '19 at 13:42
  • It does what it says. It can listen to anything that you wish to pass. I am not sure which part is unclear for you to understand. – Ranadip Dutta Feb 21 '19 at 09:42
0

Ranadip Dutta's answer meets your requirement. The listen there doesn't mean listen for incoming data, it rather means listen for connection request from client. Of course you can't use rsyslog and nc as the server at the same time, but with nc you get the messages coming from the Colas displayed as well as the characters you enter sent.

Armali
  • 18,255
  • 14
  • 57
  • 171
  • But it doesn't actually tell me how to send a string like letters to the Colas which I want to do. So I don't understand it at all. – SchnoppDog Feb 25 '19 at 07:50
  • @SchnoppDog - To _send a string like letters to the Colas_, you'd just enter it as input to `nc`. – Armali Feb 25 '19 at 07:56
  • 1
    Ok, after short googling I found some examples. Sorry that I am bad at understanding. You helped me with your answer. – SchnoppDog Feb 25 '19 at 07:57
  • Is there a option which I can use to "delete" listen on a port? Because when I try to bind a text file onto the port with "
     nc -l 8080 > listen.txt " there is a message telling me 
     ncat bind to 8080: Address already in use QUITTING 
    – SchnoppDog Feb 25 '19 at 08:22
  • @SchnoppDog - An _option_ to which program do you mean? Of course _listen_ is _deleted_ if the listening process terminates. – Armali Feb 25 '19 at 08:25