Results 1 to 5 of 5

Thread: Problem with simple TCP chat client-server

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with simple TCP chat client-server

    After 6 hours i figured what i made wrong.
    In server.cpp

    Qt Code:
    1. tcpserver->newConnection();
    To copy to clipboard, switch view to plain text mode 
    That line is wrong.


    It's should be that
    Qt Code:
    1. tcpserver->setMaxPendingConnections(1);
    2. //and add this line
    3. tcpclient = new QTcpSocket (this);
    To copy to clipboard, switch view to plain text mode 


    @Edit
    But now, a message doesn't send to anyone( client->server | server -> client)

    mhm...

    @Edit 2
    Now that i mentioned, if i delete this line
    Qt Code:
    1. tcpserver->setMaxPendingConnections(1);
    To copy to clipboard, switch view to plain text mode 
    message is sending.

    But, only with 1 pc :/

    If i tried on 2 pc connected to one router, server side get me this:
    Qt Code:
    1. QIODevice::write (QTcpSocket): device not open
    To copy to clipboard, switch view to plain text mode 
    in Application Output

    Any ideas?
    Last edited by ziele; 17th January 2016 at 16:32.

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

    Default Re: Problem with simple TCP chat client-server

    Quote Originally Posted by ziele View Post
    Qt Code:
    1. tcpserver->newConnection();
    To copy to clipboard, switch view to plain text mode 
    That line is wrong.
    Yes, as I said

    Quote Originally Posted by ziele View Post
    It's should be that
    Qt Code:
    1. //and add this line
    2. tcpclient = new QTcpSocket (this);
    To copy to clipboard, switch view to plain text mode 
    No, because you don't want to connect to clients but accept client connections

    Quote Originally Posted by ziele View Post
    But, only with 1 pc :/
    Yes, because your handler for newConnection() overwrites a single QTcpSocket variable.

    Quote Originally Posted by ziele View Post
    Any ideas?
    Yes, store the accepted connections in a list or map, not in a single pointer variable.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Problem with simple TCP chat client-server

    I figured a solution.
    I made a server to accept connect to any client not only localhost, and in client instead of localhost i connect to ip 192.168....
    And that work on 2 different PC on same LAN. THANKS FOR HELP

Similar Threads

  1. Examples for chat program, server-client?
    By Gokulnathvc in forum Newbie
    Replies: 1
    Last Post: 8th September 2011, 10:53
  2. problem in client and server model of tcp in qt
    By shakthi in forum Qt Programming
    Replies: 1
    Last Post: 26th July 2011, 15:18
  3. Replies: 1
    Last Post: 17th December 2010, 08:53
  4. server-client problem
    By sksingh73 in forum Newbie
    Replies: 2
    Last Post: 3rd July 2010, 07:18
  5. TCP server-client app problem
    By pogostick in forum Newbie
    Replies: 6
    Last Post: 25th January 2010, 08:13

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
  •  
Qt is a trademark of The Qt Company.