Page 3 of 3 FirstFirst 123
Results 41 to 58 of 58

Thread: Socket Prog

  1. #41
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Socket Prog

    Okay I will remove that one extra bracket at slot new connection, regarding string if once it is received byeach client is okay to process the data, wasting of pointers resource while sending data for that I will remove const.data while sending in socket and cross connection at client application also I will change it then I will will reply about the result wat I will get

  2. #42
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    The "wasting resources" refers to code like this
    Qt Code:
    1. te1=new QTextEdit;
    2. te1=ui->textEdit;
    To copy to clipboard, switch view to plain text mode 

    Here you create a QTextEdit and immediately lose its pointer by assigning another text edit's pointer to the variable.

    Just
    Qt Code:
    1. te1=ui->textEdit;
    To copy to clipboard, switch view to plain text mode 
    or replace all usages of
    Qt Code:
    1. te1->
    To copy to clipboard, switch view to plain text mode 
    with
    Qt Code:
    1. ui->textEdit->
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Vivek1982 (19th November 2013)

  4. #43
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Socket Prog

    Okay sure I'm going to replace all the things which is specified here...but ultimately my program logic or purpose is not having problem I hope....I have a small query here as you mentioned server sends only once data to all connected clients where as many clients will send data to server ,there is any problem in my logic all the time calling write () function from server to client or clients/clients to server at a, time

  5. #44
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    I am afraid I don't understand your question.

    Cheers,
    _

  6. The following user says thank you to anda_skoa for this useful post:

    Vivek1982 (19th November 2013)

  7. #45
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Socket Prog

    Thanks alot for the inputs, I resolved all bugs as you have mentioned in your last reply. I'm working on it now. once if this done. I will try to address that server will send data to each client specifically.Let me finish this first. Thanks for all

  8. #46
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    Quote Originally Posted by Vivek1982
    I will try to address that server will send data to each client specifically.Let me finish this first.
    Do you mean that want to send data from server to one specific client ?
    Good work on making your project work so far.

    Good Luck.

  9. #47
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Socket Prog

    Thanks Alot...let me finish first and then I will approach for specific client communication from server.. I need a support for that...always I wait for a reply
    from forum to analyse or understand whether I'm doing right or wrong... I'm very happy that forum has given me lot of support to develop application....

  10. #48
    Join Date
    May 2006
    Posts
    788
    Thanks
    49
    Thanked 48 Times in 46 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Angry Re: Socket Prog

    I found a nice code for the goal waht you need on

    Creating a multithreading QTcpServer

    http://www.qt-coding.com/2013/10/09/...-iii-and-last/

    from a spanish men..

    Qt Code:
    1. git clone https://github.com/francescmm/qt-coding.git
    To copy to clipboard, switch view to plain text mode 

  11. #49
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    I would really, strongly, advise against going into multithreading at this stage. It is completely unnessary and makes things a lot more complicated.

    Cheers,
    _

  12. #50
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Socket Prog

    Hi...can I make my small project as a package for Demo...how this can be done...A System where Qt is not installed..in that PC if we want run any qt application..what are the prerequisite procedure...

  13. #51
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

  14. #52
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Socket Prog

    Dear All,

    I need to send data to the server, which may have headers, based on the header type. Data will be sent to respective class or lineedit or text edit. But in my client application the entire data is sent across the socket. But, where as in server side I need to check the headers then handle or processs the data.
    Qt Code:
    1. Void Client:: Write()
    2. {
    3. {
    4. QByteArray DATA="001";
    5. QString linedata=ui->lineedit->text();
    6. DATA.append(linedata);
    7. socket.write(DATA.toUf8.constdata());
    8. }
    9. {QByteArray DATA="002";
    10. QString linedata=ui->lineedit_1->text();
    11. DATA.append(linedata);
    12. socket.write(DATA.toUf8.constdata());
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. Void Server::read()
    2. {
    3. {
    4. QTcpSocket *socket = qobject_cast<QTcpSocket*>( sender() );
    5. {
    6. QByteArray buffer= socket->readLine();
    7.  
    8. {
    9. if(buffer.startsWith("001"))
    10. QByteArray buf=buffer;
    11. qDebug()<<buf;
    12. buff=buffer.mid(3)
    13. Lineedit->setText(buff)
    14. qDebug()<<buf;
    15. }
    16. {
    17. if(buffer.startsWith("002"))
    18. QByteArray buf=buffer;
    19. buff=buffer.mid(3)
    20. Lineedit->setText(buff)
    21. }
    To copy to clipboard, switch view to plain text mode 


    Here the problem is when socket is read at server side. In QDebug im getting complete data like "001hello002hi"

    in the Lineedit of server complete line is printed (hello002hi) instead of giving only "hello" and actually by checking with "002" next lineedit_2 as "hi" msg to lineedit_2. How can i address this.
    Last edited by Vivek1982; 25th November 2013 at 12:17. Reason: updated contents

  15. #53
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    Thats how TCP works.
    You will have to define your own protocol or send sufficient info with the packets to be able to analyse it before processing it.


    Good Luck.
    Last edited by toufic.dbouk; 25th November 2013 at 14:23.

  16. #54
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    Quote Originally Posted by Vivek1982 View Post
    Here the problem is when socket is read at server side. In QDebug im getting complete data like "001hello002hi"
    You are not sending a new line but you are trying to read lines.

    Cheers,
    _

  17. #55
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Socket Prog

    How to insert new line please. Or Can i define the length of the data or packet to be processed every time.regarding new line I had appended "/n" at last of the data. but in the output also /n printed.I server Im calling readLine. while reading can i limit the reaqding size.. If possible, plz let me know

  18. #56
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    \n is a valid newline character, but it seems you already found that out yourself.

    Also, as toufic.dbouk already suggested (and now also discovered by yourself?) using more protocol protocol, i.e. send size information alongside the channel information that you already have.

    Cheers,
    _

  19. #57
    Join Date
    Sep 2013
    Posts
    107
    Thanks
    16
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Socket Prog

    okay.. I resolved the problem by storing data in buffer and some classes to check the data in the buffer, if data is valid it will updated on the GUI.No problem in this, its working now. I need a suggestion on my new Query.. Can we insert a image on image something like my first image is GIS MAP (screen shot of google maps after zoomin it to my location). Now there is anyway option or idea to insert a pushpin on the Image at the background. similarly like google map, inserting red pushpin for any location. How to insert pushpin image on map image(screen shot of google map).

  20. #58
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Socket Prog

    If you have a new question, create a new thread.

    Cheers,
    _

Similar Threads

  1. client/server prog using UDP
    By rajeshakula in forum Newbie
    Replies: 1
    Last Post: 12th July 2011, 12:43
  2. Build issues when qextsrialport.h is included in Linux prog
    By pupqt in forum Installation and Deployment
    Replies: 1
    Last Post: 7th April 2011, 16:48
  3. Replies: 2
    Last Post: 11th March 2010, 10:46
  4. can the image be displayed as it is in chips prog..
    By sh123 in forum Qt Programming
    Replies: 11
    Last Post: 7th February 2009, 09:15
  5. Qt Prog skip the file reading block
    By dgg32 in forum Qt Programming
    Replies: 10
    Last Post: 10th December 2008, 19:12

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.