Ethernet communication between RPi and local PC
-
the fortune server and client
seem like a good place to start.
If you use QtCreator, then they are part of the ready to compile examples in it.
-
@MrShawn @J-Hilk
thank you for your replies.
i followed the tutorial at bogotobogo and was able to establish connection. Now in my code following line:
server->listen(QHostAddress::Any, 1234);
makes the server to listen to all connections on port 1234. how to make it always listen to only one connection (local PC)? -
@vishbynature do you mean QHostAddress::LocalHost ?
-
@aha_1980
i tried that before and I get "no connection could be made because the target machine actively refused it." at client side.
Any and AnyIPv4 work normally and using ipv4 at client side by the way. Still working on server to listen only to PC......... -
@vishbynature said in Ethernet communication between RPi and local PC:
Still working on server to listen only to PC.........
Maybe you should rephrase your question. LocalHost means Server and Client run on the same machine.
It sounds like that is not what you want. What do you want then?
Regards
-
@aha_1980
ok I get what you say.
I am able to create server at RPi which listens to connections and after serving first client ( PC ), it disconnects and waits for new connection. i want it to stay connected to the same client and not look for another connection. -
@vishbynature said in Ethernet communication between RPi and local PC:
i want it to stay connected to the same client
... then just make sure that not one side (PC or RPi) disconnects for some reason.
and not look for another connection.
So effectively you want to limit your server to one connection at a time. Looks like: https://stackoverflow.com/questions/35926188/qt-tcpserver-max-clients where the answer from peppe states:
"Do not call nextPendingConnection if you're already handling enough clients."
I think that is what you should do.
Regards
-
@aha_1980
yes I agree, my code is exactly the same.
but if you remove nextpendingconnection line then they simply don't communicate. I tried to replace it with other member functions of QTcpServer but This piece of code is essential in the end.
what should i replace it with then? -
If your re-read my post you will notice that I didn't say, you should remove or replace
nextPendingConnection()
.I rather said, if you have enough clients, then don't accept further ones by not calling
nextPendingConnection()
. In your case that would mean you call it only one time for the first connection.