how to create client and server winsock in one project or use 2 winsock in one project?
-
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
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.
-
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.
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.
-
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.
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.
-
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.
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
-
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
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.
-
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
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
-
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
-
thanks a lot. anyone has such example source code. can anyone send me here. only exchange the data. thanks a lot
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. :)
-
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. :)
-
i just want an example source code with 2 winsock can be run in one project. and can communicate each other.thanks
Yes I know, my question was why. Well, have a look at non-blocking sockets.
-
thanks a lot. anyone has such example source code. can anyone send me here. only exchange the data. thanks a lot
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