Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-19-2011, 02:13 AM   #1
Gavin Harper
Registered: Feb 2010
Location: Finland
Distribution: Slackware
Posts: 169

Rep: Reputation: 24
QTcpSocket (Client) -> POSIX Sockets (Server)

I am looking for some advice on the best, most reliable way to read data from a QTcpSocket on the client side application to a port on a remote machine listening with standard POSIX sockets (Qt wasn't an option for the server side, I have written it in C).

I don't mind doing the reading/searching myself, I am simply looking for anyone who has had experience with this and what the setup in the Qt application was.

Thank you very much in advance!
Old 01-19-2011, 08:36 PM   #2
Senior Member
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,533

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
I believe QtTcpSocket is used in a manner similar to the following:
#include <QTcpSocket>


QTcpSocket* socket = new QTcpSocket;

QString serverAddr = "";
quint16 serverPort = 12345;

socket->connectToHost(serverAddr, serverPort);


char*  data         = ...;
qint64 dataSize     = ...;
qint64 bytesWritten = 0;

while (bytesWritten < dataSize)
   qint64 written = socket->write(data + bytesWritten, dataSize - bytesWritten);

   if (written == -1)
      // error; decide if you want to break from the loop, or try again.
      bytesWritten += written;
You can read more here about QTcpSocket. This class is a sub-class of QAbstractSocket, which in turn is a sub-class of QIODevice.

The links are pertinent to Qt 4.7.1; if this is not the version of Qt you are using, then please accept my apologies.

Last edited by dwhitney67; 01-19-2011 at 08:38 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
A problem creating 2 sockets in client/server rotembj Programming 1 06-09-2010 04:14 AM
Java Sockets: Help with a simple chat client/server Mega Man X Programming 6 07-15-2009 05:16 PM
client/server question (with sockets) bicycle Programming 1 11-24-2005 01:26 PM
Sockets Programing Client/Server ashucool83 Programming 9 09-30-2005 02:43 PM
Server/Client-commucation via TCP-Sockets cYbORg Programming 5 05-18-2003 06:01 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:31 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration