Results 1 to 14 of 14

Thread: socket programming

  1. #1
    Join Date
    Mar 2011
    Location
    INDIA
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default socket programming

    hey I m new to network programming.C an any one suggest some examples /material for programming..

  2. #2
    Join Date
    Oct 2010
    Location
    Belarus
    Posts
    71
    Thanks
    1
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Windows Maemo/MeeGo

    Default Re: socket programming

    Good starter example priveded by QT. See example section of QT documentation.
    Try read Qt documentation before ask stupid question.

  3. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: socket programming

    If you are after Qt network programming resources: open Qt Assistant select "Network Programming from the front page of the Qt Reference documentation. Also look at the Qt examples.

  4. #4
    Join Date
    Feb 2011
    Posts
    13
    Thanks
    2
    Thanked 1 Time in 1 Post
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: socket programming

    Hi friend,
    About socket programming, I used to do with UDP and TCP.
    With UDP, server must have one socket to communicate, it looks like:
    while(1)
    {
    int bytes_read = recvfrom(sd, buffer, sizeof(buffer), 0, 0, 0);
    }
    You can find out it on internet, so much example for it.

    With TCP, server must have one socket to communicate, and you should find out what is "listen", and "accept" functions.

    With both, you need to know multi-thread, may be POSIX thread or Win32 thread, depend on your OS which you do on.

    With them( UDP/TCP, thread) you can create a simple client-server.

    If you want to be good about socket programming, the first do no care about Qt thread, Java thread, C# thread. Let's start with APIs of OS to create thread as: pthread_create ( UNIX-Like), CreateThread( Win32).
    Good luck!

  5. The following user says thank you to posixprogrammer for this useful post:

    marco.stanzani (21st March 2011)

  6. #5
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: socket programming

    If you use Qt, there is no need for multiple thread, blocking calls or infinite loops. Everything can be done with signals and slots. This makes it much easier than using platform specific calls, and of course means your application runs under multiple platforms with a minimum of effort.

  7. #6
    Join Date
    Mar 2011
    Location
    INDIA
    Posts
    18
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: socket programming

    Thanks, but but i am completely clueless about TCP/UDP programming.
    I tried using documentation,but was'nt of much help.
    can u suggest an example or material for it.

    Thanks
    Arpit

  8. #7
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: socket programming

    What didn't you understand about the documentation?

    Did you look at the examples? Eg. fortuneclient, fortuneserver, etc?

  9. #8
    Join Date
    Feb 2011
    Posts
    31
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: socket programming

    Quote Originally Posted by posixprogrammer View Post
    If you want to be good about socket programming, the first do no care about Qt thread, Java thread, C# thread. Let's start with APIs of OS to create thread as: pthread_create ( UNIX-Like), CreateThread( Win32).
    ciao posixprog
    why you discourage using Qthreads? are there problems using Qt networking inside a Qt thread?
    thanks

  10. #9
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: socket programming

    There's no need to use Qt networking within Qt threads, as Qt networking is event-driven.

  11. The following user says thank you to squidge for this useful post:

    marco.stanzani (21st March 2011)

  12. #10
    Join Date
    Feb 2011
    Posts
    31
    Thanks
    23
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: socket programming

    thanks, but i am designing a client which communicates through two different IP ports (same IP address) doing different activities. i was thinking to encapsulate two ip soclkets inside two separate Qthread: do you see anything wrong with this?

  13. #11
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: socket programming

    I don't see why that requires two QThreads. One possible reason would be that you are going to be doing processor intensive operations taking several seconds to compute each time, but even then you could just put the processor intensive task itself in a thread, and have the socket operations in the standard event loop.

    Even if you are handling 100 connections, you can still do the task easily in a single thread.
    Last edited by wysota; 21st March 2011 at 17:59.

  14. The following user says thank you to squidge for this useful post:

    marco.stanzani (22nd March 2011)

  15. #12
    Join Date
    Feb 2011
    Posts
    13
    Thanks
    2
    Thanked 1 Time in 1 Post
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: socket programming

    Hi all,
    I don't want to discourage anyone about using Qt Thread. But I think that they need to know about thread more (each of specific OS), before using Qt Thread, and Qt Framework is great tool to do on cross OS.
    Best regards

  16. #13
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: socket programming

    Hi, I partially agree with you.
    It's true that any programmer have to know problems of the multi-threading programming.

    Recently the new C++ C++0X standard introduced multiplatform thread facilities.
    Before that many multiplatform C++ libraries/framework like Qt, ACE, boost provides similar tools.

    Native API are necessary only in very specific platform dependent problems
    A camel can go 14 days without drink,
    I can't!!!

  17. #14
    Join Date
    Feb 2011
    Posts
    13
    Thanks
    2
    Thanked 1 Time in 1 Post
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: socket programming

    Hi all,
    On our way from A to Z, often we need to pass B, C, D.... Understanding native APIs ( OS principle) may be middle point, not end point, but we must pass. I also use Qt for my application, but I still know native APIs, just be fun, happy, knowledge.
    The time is to know simple native APIs no more understand Qt APIs.
    Qt is great and will go on, I agree with this.
    Best regards!!!

Similar Threads

  1. Socket programming, please help me!
    By nthung in forum Qt Programming
    Replies: 21
    Last Post: 26th May 2010, 23:01
  2. Can any One help me? - Socket Programming?
    By vinod in forum Qt Programming
    Replies: 6
    Last Post: 18th November 2009, 09:46
  3. sending structure through udp socket programming
    By hemrajn in forum Qt Programming
    Replies: 9
    Last Post: 15th May 2009, 23:55
  4. Network Socket Programming
    By Walsi in forum Newbie
    Replies: 4
    Last Post: 19th June 2007, 10:04
  5. Problems in socket programming
    By vinod in forum Qt Programming
    Replies: 1
    Last Post: 7th March 2006, 08:09

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.