Refer this link . It has most of the code that you need to implement a simple server/client to send/receive text.
You don't always have to do the busy for loop. You could just open the socket in blocking mode and wait until text arrives (research blocking). However, this will cause the receiver to halt its execution until something comes its way, so if you plan to do something else with your program as it waits for data, you should consider using a separate thread to do the waiting part.
As an alternative, Winsock has the WM_SOCKET_NOTIFY event that can be used to get notifications when an event for that socket has occurred. This will allow you to do other things, and switch to the data reading part when it actually arrives. But designing this a bit involved if you have no experience with the Windows API.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Run it and see if it's correct.
A single send will send it only to one client.
To send to multiple clients, you have to connect multiple clients and have the server do a send to each client.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
You can use the socket file descriptor returned by accept to distinguish between multiple clients connected to the server.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Post your attempt. Let's see what the problem is.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115
Can't find the problem with only one line of code.
Post the whole program.
The one you mentioned in your first post, and the one modified to accept multiple clients.
So I have a very simple server/client program using winsock. In C++. Using MingW as a compiler.
WolfPack
Postaholic
2,051 posts since Jun 2005
Reputation Points: 572
Solved Threads: 115