Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to create client and server winsock in one project or use 2 winsock in one project?

how to create client and server winsock in one project or use 2 winsock in one project?

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminhelptutorialquestion
16 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Lost User

    Try searching the articles here on CodeProject. If you still cannot find any useful samples then try Google/Bing.

    Just say 'NO' to evaluated arguments for diadic functions! Ash

    Z Offline
    Z Offline
    zhiyuan16
    wrote on last edited by
    #3

    thanks. i searched already, all are the 2 applications, i just want one application for 2 winsock senddata. thanks

    L 1 Reply Last reply
    0
    • Z zhiyuan16

      thanks. i searched already, all are the 2 applications, i just want one application for 2 winsock senddata. thanks

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #4

      zhiyuan16 wrote:

      i just want one application

      What do you mean by one application? Even if the server and client exist on the same computer they still need to run independently. If you want to run them as a single application then you will need to create different threads for them. Much simpler to have the two separate applications which can then run independently in their own windows.

      Just say 'NO' to evaluated arguments for diadic functions! Ash

      Z 1 Reply Last reply
      0
      • L Lost User

        zhiyuan16 wrote:

        i just want one application

        What do you mean by one application? Even if the server and client exist on the same computer they still need to run independently. If you want to run them as a single application then you will need to create different threads for them. Much simpler to have the two separate applications which can then run independently in their own windows.

        Just say 'NO' to evaluated arguments for diadic functions! Ash

        Z Offline
        Z Offline
        zhiyuan16
        wrote on last edited by
        #5

        i only want to send data from client winsock, and when server receive data, then i want to do other things. that is all. so i only need one application to apply 2 winsock. thanks

        L L 2 Replies Last reply
        0
        • Z zhiyuan16

          i only want to send data from client winsock, and when server receive data, then i want to do other things. that is all. so i only need one application to apply 2 winsock. thanks

          L Offline
          L Offline
          Luc Pattyn
          wrote on last edited by
          #6

          A proper server would use threads; and a proper client would use threads too. I see no obstacles for having both the server threads and the client threads running together in one process, hence a single app. Just search good examples of server and client, then combine them. However, when you do that, what is the purpose of your sockets? it is demoted to a simple inter-thread communication scheme then. For which other solutions exist, such as queues, Windows messages, and probably many more. :)

          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

          M 1 Reply Last reply
          0
          • L Luc Pattyn

            A proper server would use threads; and a proper client would use threads too. I see no obstacles for having both the server threads and the client threads running together in one process, hence a single app. Just search good examples of server and client, then combine them. However, when you do that, what is the purpose of your sockets? it is demoted to a simple inter-thread communication scheme then. For which other solutions exist, such as queues, Windows messages, and probably many more. :)

            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

            Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

            M Offline
            M Offline
            Moak
            wrote on last edited by
            #7

            Luc Pattyn wrote:

            A proper server would use threads

            I often handle both client and server in a single thread context in an application. This is called asynchronous networking or non-blocking sockets... e.g. used by lighttpd.

            Chat in Europe :java: Now with 24% more Twitter

            L 1 Reply Last reply
            0
            • M Moak

              Luc Pattyn wrote:

              A proper server would use threads

              I often handle both client and server in a single thread context in an application. This is called asynchronous networking or non-blocking sockets... e.g. used by lighttpd.

              Chat in Europe :java: Now with 24% more Twitter

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #8

              you're right, one can use asynchronous operations instead of threads. I tend to prefer threads as asynchronous operations seem more complex, but I do realize they can be a good choice, and have the advantage of saving on stack memory at the expense of some more code. Also, when borrowing existing code in order to join a server and a client, I expect a thread-oriented approach would be easier to merge than an asynchronous one. :)

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

              Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

              M 1 Reply Last reply
              0
              • L Luc Pattyn

                you're right, one can use asynchronous operations instead of threads. I tend to prefer threads as asynchronous operations seem more complex, but I do realize they can be a good choice, and have the advantage of saving on stack memory at the expense of some more code. Also, when borrowing existing code in order to join a server and a client, I expect a thread-oriented approach would be easier to merge than an asynchronous one. :)

                Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                M Offline
                M Offline
                Moak
                wrote on last edited by
                #9

                Luc Pattyn wrote:

                I expect a thread-oriented approach would be easier to merge than an asynchronous one.

                It's just copy and paste. Here is a server/client example (last two code snippets), which you can join together in a single application. It wouldn't be very different with MFC's CAsyncSocket or QT's networking classes. I think the asynchronous networking model has is strengths with applications, where you want to focus on protocol an functionality and less on synchronisation and timing. /M

                Chat in Europe :java: Now with 24% more Twitter

                L 1 Reply Last reply
                0
                • M Moak

                  Luc Pattyn wrote:

                  I expect a thread-oriented approach would be easier to merge than an asynchronous one.

                  It's just copy and paste. Here is a server/client example (last two code snippets), which you can join together in a single application. It wouldn't be very different with MFC's CAsyncSocket or QT's networking classes. I think the asynchronous networking model has is strengths with applications, where you want to focus on protocol an functionality and less on synchronisation and timing. /M

                  Chat in Europe :java: Now with 24% more Twitter

                  L Offline
                  L Offline
                  Luc Pattyn
                  wrote on last edited by
                  #10

                  yes, OK. Great link BTW. :)

                  Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                  Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                  1 Reply Last reply
                  0
                  • Z zhiyuan16

                    i only want to send data from client winsock, and when server receive data, then i want to do other things. that is all. so i only need one application to apply 2 winsock. thanks

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #11

                    As Luc says, why use sockets within a single application when you can just use a message queue, shared memory etc. However, since you are doing the implementation it is entirely your choice.

                    Just say 'NO' to evaluated arguments for diadic functions! Ash

                    Z 1 Reply Last reply
                    0
                    • L Lost User

                      As Luc says, why use sockets within a single application when you can just use a message queue, shared memory etc. However, since you are doing the implementation it is entirely your choice.

                      Just say 'NO' to evaluated arguments for diadic functions! Ash

                      Z Offline
                      Z Offline
                      zhiyuan16
                      wrote on last edited by
                      #12

                      thanks a lot. anyone has such example source code. can anyone send me here. only exchange the data. thanks a lot

                      M L 2 Replies Last reply
                      0
                      • Z zhiyuan16

                        thanks a lot. anyone has such example source code. can anyone send me here. only exchange the data. thanks a lot

                        M Offline
                        M Offline
                        Moak
                        wrote on last edited by
                        #13

                        zhiyuan16 wrote:

                        anyone has such example source code. can anyone send me here.

                        What are your requirements? We know how you want to do it, but not what. Could you describe more detailed what it is you want to solve, for example if you have a practical application problem or experimenting with winsock, then it is much easier to recommend something. :)

                        Chat in Europe :java: Now with 24% more Twitter

                        Z 1 Reply Last reply
                        0
                        • M Moak

                          zhiyuan16 wrote:

                          anyone has such example source code. can anyone send me here.

                          What are your requirements? We know how you want to do it, but not what. Could you describe more detailed what it is you want to solve, for example if you have a practical application problem or experimenting with winsock, then it is much easier to recommend something. :)

                          Chat in Europe :java: Now with 24% more Twitter

                          Z Offline
                          Z Offline
                          zhiyuan16
                          wrote on last edited by
                          #14

                          i just want an example source code with 2 winsock can be run in one project. and can communicate each other.thanks

                          M 1 Reply Last reply
                          0
                          • Z zhiyuan16

                            i just want an example source code with 2 winsock can be run in one project. and can communicate each other.thanks

                            M Offline
                            M Offline
                            Moak
                            wrote on last edited by
                            #15

                            Yes I know, my question was why. Well, have a look at non-blocking sockets.

                            Chat in Europe :java: Now with 24% more Twitter

                            1 Reply Last reply
                            0
                            • Z zhiyuan16

                              thanks a lot. anyone has such example source code. can anyone send me here. only exchange the data. thanks a lot

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #16

                              There are lots of sample winsock applications, both here on CodeProject and out where Google will find them. However there probably will not be many with both client and server code in the same app. As has been suggested more than once, you will need to take the code for both halves and put it together for your requirements.

                              Just say 'NO' to evaluated arguments for diadic functions! Ash

                              1 Reply Last reply
                              0
                              Reply
                              • Reply as topic
                              Log in to reply
                              • Oldest to Newest
                              • Newest to Oldest
                              • Most Votes


                              • Login

                              • Don't have an account? Register

                              • Login or register to search.
                              • First post
                                Last post
                              0
                              • Categories
                              • Recent
                              • Tags
                              • Popular
                              • World
                              • Users
                              • Groups