LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 01-19-2011, 02:13 AM   #1
Gavin Harper
Member
 
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
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

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

...

QTcpSocket* socket = new QTcpSocket;

QString serverAddr = "192.168.1.100";
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.
   }
   else
   {
      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.
 
  


Reply


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

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:38 AM.

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