VOOZH about

URL: https://www.geeksforgeeks.org/cpp/two-way-communication-between-client-and-server-using-win32-threads/

⇱ Two way communication between Client and Server using Win32 Threads - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Two way communication between Client and Server using Win32 Threads

Last Updated : 12 Jul, 2025

It is possible to send data from the server and receive a response from the client. Similarly, the client can also send and receive data to-and-from. Here we will discuss the approach using Win32 Threads in C/C++.

Approach

  • Use CreateThread function which creates a new thread for a process.
  • The CreateThread method must specify the starting address of the code that the new thread is to execute. Following is the prototype of CreateThread function:
  • Then using WaitForSingleObject function that returns message in form of object received from client, to receive data from client. Following is the prototype of WaitForSingleObject function:


Creating the Server program

In the Server Program, we will be using two threads, one for Sending data to the client and another for Receiving data from the client. The process of communication stops when both Client and Server type exit.

Run the ServerApplication.cpp file using the command:

g++ ServerApplication.cpp -lws2_32

Creating the Client Program

In the Client Program, we will be using two threads one for Sending data to the server and another for Receiving data from the server. The process of communication stops when both Server and Client type exit.

Run the ClientApplication.cpp file using the command:

g++ ClientApplication.cpp -lws2_32

Output:

After communication between Server and Client

👁 Image

The left side command prompt is the ServerApplication and the right side command prompt is the ClientApplication.

Comment