Итак, у меня есть два приложения, одно написано на C ++ с использованием Qt5, а другое написано на Java.Приложение C ++ действует как клиент, который подключается к объекту ServerSocket
в приложении java, которое затем создает сокет из соединения.Затем, когда я пытаюсь отправить строку на сервер, я должен либо отправить строку повторно (например, 20000 раз), либо сервер вообще ничего не получает.
QString s = " This is a test string that will be sent to the server upon connection\n";
QTcpSocket *sock = new QTcpSocket;
sock->connectToHost(QHostAddress::LocalHost, 5000, QIODevice::ReadWrite);
sock->waitForConnected(5000);
QTextStream out(sock);
while(!sock->waitForBytesWritten(3000)) {
out << s << endl;
}
Если приведенный выше код не даст никаких результатов, следующие строки дают сегментированные строки, а также дубликаты полученных строк для сервера:
QString s = " This is a test string that will be sent to the server upon connection\n";
QTcpSocket *sock = new QTcpSocket;
sock->connectToHost(QHostAddress::LocalHost, 5000, QIODevice::ReadWrite);
sock->waitForConnected(5000);
QTextStream out(sock);
do {
out << s << endl;
} while(!sock->waitForBytesWritten(3000) | 1);
Сервер представляет собой простую Java-программувот так:
ServerSocket ss = new ServerSocket(5000);
Socket s = ss.accept();
DataInputStream in = new DataInputStream(s.getInputStream());
while (true){
String tmp = in.readUTF();
System.out.println(tmp);
if (tmp.contains(" ")){
break;
}
Я ожидаю, что результат будет простым This is a test string that will be sent to the server upon connection
;однако в результате получается либо ничего, либо что-то в этом роде:
his is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
This is a test string that will be sent to the server upon connection
Есть ли у вас какие-либо идеи относительно того, как я могу решить эту проблему?