Sockets per client?

Started by
2 comments, last by laeuchli 22 years, 9 months ago
I want to write a simple chat program to test my winsock programming, but I have a question. Do I need to create a socket a client in the server code. If I have have clients do I need 5 sockets??
Advertisement
You seemed to miss some words in there, but yes, you need a socket for each client that is connected to the server.

Or you could make it peer to peer and each peer will have sockets to every other peer, unless you use a ring, and then each peer has a socket to the next and previous peers in the ring (this is a silly approach btw ; )

G''luck,
-Alamar
Hi,
You need one socket per client connection.
Server code should have something like:
#define MAX_CONN 5
struct SOCKET s[MAX_CONN];
Now s can hold 5 connections.
Then go from there.
Also some advice:
Always try to test your pgm on a live LAN.
Use a sniffer to check your packets.
and
CHECK THE RETURNS OF WINSOCK FUNCTIONS!!!
This helped me alot when I was coding my chat pgm.
Regards,
UglyCode.
If you use TCP then you need a socket per client. If you use UDP then one socket can handle them all.

Of course since UDP isn''t reliable it might not be good enough for your application

-Mike
-Mike

This topic is closed to new replies.

Advertisement