QTCP server ... possible run more than one?
-
@Christian-Ehrlicher ok thanks ... my misunderstand ....
but starting poit can beclient = server->nextPendingConnection(); chooseClient = client->peerAddress().toString(); QString client1 = "19x.16x.51.xx1"; QString client2 = "19x.16x.51.xx2"; QString client3 = "19x.16x.51.xx3"; QString client4 = "19x.16x.51.xx4"; if(chooseClient == client1){ some stuff1... /* how to assign actual connection to right socket1 with these ip?? */ } else if(chooseClient == client2) { some stuff2../* how to assign actual connection to right socket2 with these ip?? */ } etc etc
after newconnection .....
I don't understand how I can distinguish one connection from another .... so let's assume that a client disconnects and then reconnects again .... the same call to newconnection will have to tell which client it is and it seems to me that in order to have a unique name getperradress is the only street ....@gfxx said in QTCP server ... possible run more than one?:
after newconnection .....
No, this is crap.
Again: create a worker object for each connection and do your handling in there.
-
@gfxx said in QTCP server ... possible run more than one?:
I don't understand how I can distinguish one connection from another
For each connection you get a QTcpSocket. Don't know what the problem is. Can you explain why you need to know whether exact same client connects again? What is your use case?
"it seems to me that in order to have a unique name getperradress is the only street" - you can have more than one connection from same IP. A connection is defined by IP + port.
@jsulm because I share data per client request and data need to go to that client .... so for know what type of data need to send, need to know if that client is connect or not .... plus when receive data need to know witch client send that data .... because packet not contain client id so not possible filter it ....
Sorry but for me socket is a quite new affairs ....
-
@gfxx said in QTCP server ... possible run more than one?:
after newconnection .....
No, this is crap.
Again: create a worker object for each connection and do your handling in there.
@Christian-Ehrlicher .... you are in right
-
@gfxx said in QTCP server ... possible run more than one?:
I don't understand how I can distinguish one connection from another
For each connection you get a QTcpSocket. Don't know what the problem is. Can you explain why you need to know whether exact same client connects again? What is your use case?
"it seems to me that in order to have a unique name getperradress is the only street" - you can have more than one connection from same IP. A connection is defined by IP + port.
@jsulm for me is almost all new ..... so how can i figure out which client machine connected? .... auto reply: if build a sokClass and new istance of class every newconnection .... no need to know that .... so
void MainWindow::initServer(){ server = new QTcpServer(this); client = new Sokclient(); client1 = new Sokclient(); client2 = new Sokclient(); if (!server->listen(QHostAddress("192.1xx.xx.xxx"), xxx)){ QString ipi = "no connection"; //return; } else{ /**** these is all wrong .... how can connect nexpendingconnection to new SockClient class object client, client1 and client2?? *****/ //connect(server, &QTcpServer::newConnection, this, [=](){client = server->nextPendingConnection(); new_con(); qDebug() << " connect ";}); //connect(client, &QTcpSocket::readyRead, this, &MainWindow::readSocket); //connect(client, &QTcpSocket::disconnected,this, &MainWindow::discardSocket); //connect(ui->pbtn_F_send, SIGNAL(released()), this, SLOT(sendOrder()));
then need connect mainwindows signal to SokClient class slot ....
-
@jsulm because I share data per client request and data need to go to that client .... so for know what type of data need to send, need to know if that client is connect or not .... plus when receive data need to know witch client send that data .... because packet not contain client id so not possible filter it ....
Sorry but for me socket is a quite new affairs ....
@gfxx said in QTCP server ... possible run more than one?:
when receive data need to know witch client send that data
You know from which client you got data because for each client you have a dedicated QTcpSocket instance (as I already wrote above). So, you simply write to the same socket from which you got data...
-
@gfxx said in QTCP server ... possible run more than one?:
when receive data need to know witch client send that data
You know from which client you got data because for each client you have a dedicated QTcpSocket instance (as I already wrote above). So, you simply write to the same socket from which you got data...
@jsulm sorry non understand ...
connect(server, &QTcpServer::newConnection, this, [=](){client = server->nextPendingConnection()
call "client" on mainwindows ...... next connection can't be "client" .... at least need to be "client2" ..... how can i pass server->nextpendingconnection once to client2, then to client3 etc etc??
-
Again: create a worker object which handles each connection for you, store the worker objects in a container if you really need to access them from anywhere else. Learn basic c++ principles.
-
@jsulm sorry non understand ...
connect(server, &QTcpServer::newConnection, this, [=](){client = server->nextPendingConnection()
call "client" on mainwindows ...... next connection can't be "client" .... at least need to be "client2" ..... how can i pass server->nextpendingconnection once to client2, then to client3 etc etc??
@gfxx said in QTCP server ... possible run more than one?:
next connection can't be "client" .... at least need to be "client2"
Nothing stops you from storing all the QTcpSocket instances in a container (like QVector for example), like @Christian-Ehrlicher suggested already...
-
@gfxx said in QTCP server ... possible run more than one?:
next connection can't be "client" .... at least need to be "client2"
Nothing stops you from storing all the QTcpSocket instances in a container (like QVector for example), like @Christian-Ehrlicher suggested already...
@jsulm thanks .... but these means every time need one istance need to choose the right from qvector ... or qlist or other container .... so problem is almost the same .... why start soket1, soket2, soket3 etc etc and never stop it is crap like Christian talk? really not understand ....
-
@jsulm thanks .... but these means every time need one istance need to choose the right from qvector ... or qlist or other container .... so problem is almost the same .... why start soket1, soket2, soket3 etc etc and never stop it is crap like Christian talk? really not understand ....
@gfxx said in QTCP server ... possible run more than one?:
but these means every time need one istance need to choose the right from qvector
Why should you need one of these instances?
-
@jsulm thanks .... but these means every time need one istance need to choose the right from qvector ... or qlist or other container .... so problem is almost the same .... why start soket1, soket2, soket3 etc etc and never stop it is crap like Christian talk? really not understand ....
@gfxx said in QTCP server ... possible run more than one?:
really not understand
And I don't understand the problem. Can you explain when you need these instances?
-
@gfxx said in QTCP server ... possible run more than one?:
really not understand
And I don't understand the problem. Can you explain when you need these instances?
@jsulm because data exchange is quite continuos and whitout any sort of regularity in format and type .... sometime file, sometime messages/string, sometime array/data structures .... if socket was interrupt need to have an advices and if need need to restart it 24/24 hour, 7/7 days ....
-
@jsulm because data exchange is quite continuos and whitout any sort of regularity in format and type .... sometime file, sometime messages/string, sometime array/data structures .... if socket was interrupt need to have an advices and if need need to restart it 24/24 hour, 7/7 days ....
@gfxx said in QTCP server ... possible run more than one?:
ecause data exchange is quite continuos and whitout any sort of regularity in format and type .... sometime file, sometime messages/string, sometime array/data structures .... if socket was interrupt need to have an advices and if need need to restart it 24/24 hour, 7/7 days ....
This does not answer any of our questions and does not even give a hint on what exact problems you have when you do a proper c++ encapsulation of the sockets in a worker thread... but maybe my c++ knowledge is to small.
-
@gfxx said in QTCP server ... possible run more than one?:
ecause data exchange is quite continuos and whitout any sort of regularity in format and type .... sometime file, sometime messages/string, sometime array/data structures .... if socket was interrupt need to have an advices and if need need to restart it 24/24 hour, 7/7 days ....
This does not answer any of our questions and does not even give a hint on what exact problems you have when you do a proper c++ encapsulation of the sockets in a worker thread... but maybe my c++ knowledge is to small.
@Christian-Ehrlicher said in QTCP server ... possible run more than one?:
... but maybe my c++ knowledge is to small.
these is for make me laugh! thanks
so i try with worker thread and mySok class ... qabstractsocket::state:unconnected for kill worker ...
-
@Christian-Ehrlicher said in QTCP server ... possible run more than one?:
... but maybe my c++ knowledge is to small.
these is for make me laugh! thanks
so i try with worker thread and mySok class ... qabstractsocket::state:unconnected for kill worker ...
@gfxx said in QTCP server ... possible run more than one?:
so i try with worker thread
Again: I never ever told you to use threads and will not do so anywhen in the future for such a task!
-
@gfxx said in QTCP server ... possible run more than one?:
so i try with worker thread
Again: I never ever told you to use threads and will not do so anywhen in the future for such a task!
@Christian-Ehrlicher said in QTCP server ... possible run more than one?:
Again: I never ever told you to use threads and will not do so anywhen in the future for such a task!
then I think I don't understand the term ... English is not my language ... you talk about worker thread .... but you mean the main thread on which the program works? .... because I understant only "worker.movetothread....." .... sorry ... so your solution is more istance of myClient class ..... so myclient1, myclient2..... because I know other pc and can choose them from ip adress and port number .... fixed istances for fixed ip adress&port number .... is what you means?
-
Hi,
@Christian-Ehrlicher wrote: "worker object". It does not require any thread. It represents the class that will implement whatever needs to be done with your socket.
-
Hi,
@Christian-Ehrlicher wrote: "worker object". It does not require any thread. It represents the class that will implement whatever needs to be done with your socket.