UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

#1 2013-09-26 03:20 AM

holystone
Member
Registered: 2013-09-26
Posts: 2

Client/Server programming

Hi all,

This question is actually part of my assignment. I have to make a server and a client. The client will act as a server also and will accept connections from other peers. The main server will mantain a list of every client connected to it and as soon as a client connects to server, the server will send an updated list to all the clients. This list will contain the names of all the cilents connected to it, their ip address and the port number they are using for listening. I have made a linked list but I am not sure how to broadcast it to every client. Somebody please help. Thanks.

Offline

#2 2013-09-26 12:24 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: Client/Server programming

This is using TCP?  If so, you can't really "broadcast" it, per se...  You'll just have to send messages down the TCP connections of every client that's currently connected...

You'll have to come up with some app-level protocol to distinguish your message types, and separate them from each other...  You'll find lots of discussion in old threads here about separating messages on TCP streams, but basically your two choices are: use a delimiter of some sort to mark the end of each message; or, prefix each message with a fixed-length header of some sort, which gives the full size of the variable-length message...

Once you have that protocol in place, it's just a matter of formatting your list of clients as a message to send, and then sending it out to all connected clients...

Offline

#3 2013-09-27 10:36 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: Client/Server programming

In this particular case it's probably better and easier to send client updates to each peer
instead of sending the whole list everytime. Then let each peer manage and update their
local linked list themselves. You only have to send the full client list to the new client.
(But you can also implement that by sending multiple "new client" messages.)

Also, because every client is a server too, it seems like it's some kind of distributed peer
to peer system. Are you sure there is meant to be one central server? I would make one
program and not two, making it so that every client can connect to any other client to
join the network.

Offline

#4 2013-09-28 02:45 AM

holystone
Member
Registered: 2013-09-26
Posts: 2

Re: Client/Server programming

Thanks for the replies. There is only one program, The server here is only maitianing the list, so that each client can see each others ip addresses and lisening port numbers and can connect within themselves. I am not sure if I will be able to explain properly but this is how it is supposed to work

1) In command prompt I will write "s <server port number>", and my program will work as a server.
2) I will open other teminals and write "c <client port number>" and my program will work as clients.
3) Each client will then register itself on the server running in step 1 by using the command "register <server ip address> <server port number>"
4) As soon as a new client registers itself on server, the server will update the list and send the updated list to every client; containing the name, ip address and listening port number of every connected client.

Offline

Board footer

Powered by FluxBB