UDP broadcast server-client example.

UDP broadcast server-client example.

Post by Fredrik Blomsted » Sat, 06 May 2000 04:00:00


I want to implement a server-client UDP connection
over SunOS that uses broadcast. For now I think
that an implementation for this will look like :

(For server) :

1) Create socket
s = socket(AF_INTE,SOCK_DGRAM,0);

2) Set broadcast.
int enable = 1;

3) Bind one port
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = INADDR_ANY;
sin.sin_port = htons(1234);
bin(s,(struct sockaddr *)&sin,sizeof(sin));

5) LAN use INADDR_BROADCAST (not care of ioctl...)
dst.sin_family = AF_INET;
dst.sin_port = htons(1234);
dst.sin_addr.s_addr = INADDR_BROADCAST;

6) Send message to all listening clients...
sendto(s,buf,beflen,0,(struct sockaddr *)&dst,sizeof(dst));

Is this correct??? Anyone who have some fine example?

(For client(s)) :

Step 1, 3 and then just listen on broadcast, or what?
How will this initialization look like.

Please help.


Greetings Fredrik.


UDP broadcast server-client example.

Post by Fredrik Blomsted » Sat, 06 May 2000 04:00:00

The problem is solved.

Thanks for your time.

Greetings Fredrik.


1. searching broadcast server and client example

Hi !

I'm lookin for an example of a send-only-broadcast-server
and a matching client.

The server shall not send at all and the client shall only
receive the messages from the socket. I don't manage to
get the socket configured right, so I can only broadcast
to clients not being run on the same machine as the server.

Maybe there's something wrong in splitting up combined servers
which include the client code...

All I got is the book "Unix Network Programming" and I think, there
must be better examples ...  (the book is no help on broadcast related

So if someone has a short example of a client and a server, I'd be
glad to get a copy...

(If I can get some DOC on this by ftp, a pointer is ok too...)

Thanks in advance !


2. xinetd now broken? RH 7.3

3. Looking for example UDP file transfer code (both client and server) in C

4. Auto baud and getty

5. shortest possible reliable-UDP client/server example

6. Looking for xcoral editor

7. examples on IPv6 udp client/server sockets wanted

8. FAQ / Instructions on making a PC dual boot....

9. Can someone give me a example of udp program ,just sent a string to client?

10. Need Client - Server Example Code

11. TCP/IP client/server code examples.

12. Simple TCP Client/Server example

13. Example of simple TCP socket client/server program