Unsolved How does readyRead() know about which socket is to read?
-
-
@MokJ does what you mean is how to identify the socket which sent the signal ? As you are at server side you should know the clients which are connected to the server.
-
@Gojir4 yeas thats exactly is my point.
I want to make sure on server side that which socket has sent the signal or message .
Thanks for quick response . -
@MokJ so when you accept the connection from the socket, you can store it in a list or a map, with the socket descriptor or another id. Then retrieve it from the list when readyRead is called. Or you can get inspiration from Qt examples like this one http://doc.qt.io/qt-5/qtnetwork-network-chat-example.html. im sorry im on the phone so i cannot provide some code sample
-
@Gojir4 thanks very much . I'd look into it.
and If you can give any clue or document about how readyRead() works internally , that'd be a big help. -
I don't really understand, I think there are two separate threads on this issue... ??
I have already answered how you can detect client in https://forum.qt.io/topic/90324/how-readyread-know-about-from-which-socket-it-is-called
-
@JonB I wouldn''t know about the other thread , But this is what I'm having trouble with and I'm definitely trying to apply all the suggestion to get the solution.
and again talking about readyRead(), If I create a new QTcpSocket to read , just read at server side, I mean an unique socket just for reading , is it possible ? -
Have you looked at the examples?
-
@MokJ
There must be two similar threads on-going with the same question then!I'm not sure what you are asking now, but if you want to know "which client is a given socket connected to" I stand by my statement in the other thread:
Given a
QTcpSocket
, from http://doc.qt.io/qt-5/qabstractsocket.html there are methods likelocalAddress/Port()
&peerAddress/Name/Port()
to see what the socket is connected to at server/client sides.Otherwise, from the "native socket descriptor" passed to
socket->setSocketDescriptor(this->socketDesc)
, I assume this is the native "SOCKET" type you can access thestruct sockaddr_in
to get this information.Also, just to be clear if you are not sure about this, with TCP sockets if you have multiple clients connected to one server each connection has a distinct, separate connected socket. So when you call
socket->readRead()
orsocket->readAll()
the socket is for one particular connected client (the one when theQTcpSocket
was initially created). -
yes @kshegunov I have ,
Thanks @JonB
I got it now