Write a TCP Server and Client in Python. To understand the topic in detail, let’s first have a quick look at the socket classes present in the Python SocketServer module. It is a framework that wraps the Python socket functionality.
So I've been using stackoverflow for over 5 years now and this maybe the best response I've ever come across on it. Well written and explains a lot. I was trying to figure out why I was getting slow data throughput via modbus when I could get 37k+ read/writes per minute over straight serial at 115220 baud. Thanks for the benchmarking code as well, I was unaware of of modbus-tk. I've used pymodbus for a while via TCP and has worked great and fast, but testing some serial stuff and was running quite slow, but this answered quite a bit questions for me, so thanks. – Aug 21 '14 at 14:15.
Sorry, I should have been more specific. I was using pyserial which is what I meant by straight serial. I was just writing a time stamp on one machine and reading from another.
I figured it would be faster but not as fast as it had been running. I did test modbus in both ASCII and RTU mode but didn't see much of an improvement. I also testing via pyserial to see if that could be the bottleneck as I had mentioned TCP in pymodbus I can run way faster. I also tested sync vs. Async server and only noticed a slight improvement on the async. – Aug 26 '14 at 18:50. It really depends on what application you're using, and what you're trying to achieve.
Pymodbus is a very robust library. It works, and it gives you a lot of tools to work with. But it can prove to be a little intimidating when you try to use it. I found it hard to work with personally.
It offers you the ability to use both RTU and TCP/IP, which is great! MinimalModbus is a very simple library. I ended up using this for my application because it did exactly what I needed it to do.
It only does RTU communications, and it does it well as far as I know. I've never had any trouble with it. I've never looked into Modbus-tk, so I don't know where it stands. Ultimately though, it does depend on what your application is.
In the end I found that python wasn't the best choice for me.
Example You can create a TCP server using the socketserver library. Here's a simple echo server.