Click here to Skip to main content
12,762,900 members (39,725 online)
Click here to Skip to main content
Add your own
alternative version


77 bookmarked
Posted 10 May 2004

NetFM - Internet Broadcasting

, 10 May 2004
Rate this:
Please Sign up or sign in to vote.
Basic framework for implementing Internet Broadcasting using UDP & Multiple Unicasting


I call this project NetFM. I hope the name doesn't sound stupid and nobody will drag me to court over trademark violations.

This project was made for submission as my semester 6 project for B.Tech Computer Science. It provides the basic framework for implementing Internet Broadcasting. I hope that the person who is reading this knows about Internet Broadcasting and the basics of network programming. I will be using SHOUTcast and Winamp as examples to explain about Internet Broadcasting. I was inspired by Winamp TV/Radio services (SHOUTcast) when I selected this topic.

Internet Broadcasting is your normal TV & Radio but on the Internet. The medium of transmission is the internetwork, LANs or WANs, instead of air/cable. And that ladies and gentlemen is the biggest trouble since most of us do not have sufficient bandwidth to receive real-time audio/video!

And also because the Internet is a packet-based network and was never made for transmission of real-time multimedia. Thus it is very difficult to achieve the same levels of quality as conventional TV transmission.

Probably you will experience problems in understanding what I am trying to say and since I have 3 programs in this project you may experience troubles in trying out the programs. I will do my best to keep matters as simple as possible. Please forgive me if you find my article difficult to follow.


During the early stages of this project (before programming started) I read a lot about audio formats, network programming( especially UDP) and Multicasting. Please checkout Multicasting, it will help you to better understand this project.

Using the code

Please read the project will help you a lot :-) . I have attached only the necessary pages from the report. Please contact me if you would like to read the entire report.

Before running the programs copy the file "textnewsbroadcastfile.txt" which I have attached in Download source & resources to your "c" drive. It provides news updates along with the audio stream.

How to use the programs

Ok its very easy to use the programs since I have made a "settings" button for all the 3 programs and once you have made the settings its as easy as riding a bicycle.

I advise that the first time when you run the programs keep the default settings. e.g.- "loopback" for IP address in the programs and run all 3 programs on the same computer ( don't worry...its a network program...will work anywhere on this planet...wherever TCP/IP is available). If you can get them working on a computer try it out on a LAN, or the Internet.

The 3 programs

1. StationServer. It is a server program very much like , it keeps track of channels (which are essentially broadcast programs) and provides the Receiver programs with the list of all channels whenever requested. Only one instance of this program is needed for implementing the broadcast network.

A channel is identified by the IP address of the computer on which the broadcast program is running and the TCP port on which it receives connection requests... The StationServer program does no more than receive details from the broadcast programs and add them after some processing to the ListBox that you can see in the above image.

Each channel has a descriptive name about its content (e.g. World News) , socket address to contact for listening to the broadcast (e.g. , number of active listeners and total number of listeners the broadcast program can support (e.g. 2/10) .

I am using Multiple Unicasting here, since Multicasting requires the support of "Multicast Routers" which are few in number over the internet.

Maximum Listeners= (Bandwidth available to Broadcast program) / (Rate of transmission).

This project uses MP3 file format. So transmission rate=bitrate of the MP3 file.

All other programs... the Mediaserver (broadcast program) and Receiver connect to the StationServer. You can run any number of Mediaservers and Receivers but only one StationServer.

The StationServer acts as the central server for this broadcast network.

2. Mediaserver .This is the broadcast program. On startup it informs the StationServer about its port details, content, maximum number of receivers. It must be loaded with a playlist file...I have provided an example in Download source & resources. The StationServer IP and Port must be set to that of the StationServer program. Otherwise no receiver can connect to this channel.

The broadcast program "plays" i.e. move the file pointer at the bitrate of the MP3 file. Please note that there is no audio output in the broadcast program. You must run a receiver to checkout that things are working properly.

Receivers get the list of channels from the StationServer and connect to a selected Mediaserver. On connection to the Mediaserver the receiver is add to the "Receiver List" and an update is sent to the StationServer.

In the broadcast program the MP3 file is loaded in memory and at intervals of 1 second packets of fixed size(=bitrate of MP3 file) , are sent to the Receiver over UDP. You can see the "Track Progress" bar that displays the status of current file. When a song ends, a new one is loaded from the playlist. You can also select a song from the playlist and press the "Load Selected Track" to manually stop transmission of current song and load a new file.

There are separate threads for audio broadcast and news broadcast. The source for the news broadcast is the file "c:\textnewsbroadcastfile.txt" in which the first entry is the number of news items followed by news snippets separated by "#" symbols.........

I am not including any code in the explanation of the working since the code is very simple and you need to run the programs a couple of times to understand how it works. Once you do that, checkout the source files, I have given as many comments as required, & the variables have been named such that they are easy to understand. Probably you will find my way of programming rather unconventional :-) Most importantly, this article is already too big !!

3. Receiver . This program connects to the StationServer and obtains the list of channels on air. Then you can select any channel and the Receiver will try to connect to that particular channel.

The receiver will be added to the list of the broadcast program and it will receive data packets over UDP containing both audio content and news items.

The news items are display in the "NEWS Bar", the audio packets are buffered for playback, the buffer size can be set in the "settings" . Please be patient while the program buffers. You can see the buffer progress on the interface. After the first buffering you can listen to the audio being transmitted by the broadcast program (Mediaserver).

I use MCI for the playback of audio stream. The packets coming over the network are buffered and when the buffer limit is reached, written to disk and then MCI is used for playback. I write the buffer to disk only because I didn't find any way to implement playback from memory. Though I have kept the disk access to a minimum , it would still be a big improvement if any of you can suggest me some method to achieve playback of the memory buffer. The writing to disk alternates between 2 files. while one is written to, the other is played.

When you disconnect from a broadcast, the Mediaserver is contacted and its list updated, the StationServer is updated and, the receiver can now select another channel to listen to.

I made a jpeg image to explain how control and data flows...please note that I have depicted only a subset of the project working....

Important Points while trying the Programs

  1. You must copy the resource file "textnewsbroadcastfile.txt" to the "c" looks something like this...
    number of news items
    news item 1
    news item 2

    The MediaServer uses this file for news broadcast..( "c:\textnewsbroadcastfile.txt") you can modify it as required.....but keep the format otherwise the MediaServer program will get struck/crash/whatever.

  2. Make playlist before you start the MediaServer program...the program accepts only filenames with extension "*.srp" or "*.m3u"...

    "*.srp" is of the form...

    E:\MP3\jukebox\Linkin Park\Linkin Park - Papercut.mp3
    E:\MP3\jukebox\Linkin Park\Linkin Park - Pushing Me Away.mp3
    E:\MP3\jukebox\Linkin Park\Linkin Park - Somewhere I Belong.mp3
    E:\MP3\jukebox\Linkin Park\Linkin Park - By Myself.mp3
    E:\MP3\jukebox\Linkin Park\linkin park - crawling.mp3

    or use the Winamp playlist "*.m3u" provided it contains only the full pathnames and no other entries. Just make sure that the full file pathname is in the playlist.

  3. The StationServer should be started first. Followed by Mediaservers and Receivers. (any number of them) you can run all these on the same to get audio output you must connect to some channel
  4. The MediaServer makes the assumption that all playlist entries are CBR MP3s, no support for VBR files.
  5. Please click on the "Disconnect" button before you exit the Receiver program, otherwise the temporary files remain on the hard disk.

    Right now I can't think of any more precautions to take :-) If you have trouble in running the programs please contact me. I will rewrite the article as required.

Points of Interest

In the Mediaserver I don't use a linked list to add/remove clients from the broadcast. Instead I use the ListBox itself to do all the work of adding, searching, removing receivers from the broadcast list. Addstring to add receiver, FindStringExact to search for an entry in the list and DeleteString to remove the receivers from the broadcast list.

For the temporary files in the receiver program I use the UDP port numbers of the receiver program as filename, this helps in running as many receiver programs as you would like to on the same computer without them conflicting.

Improvements Possible

Multiple Unicasting consumes a lot of bandwidth, thus from an economical point of view, this project is damn costly to implement on large scale. Small scale implementation using low bitrate MP3's news, talk-shows with 8-16kbps can be easily implemented at colleges and small businesses. On LANs, since bandwidth is no problem, it can be easily used.

I will try to implement Multicasting and Video transmission and extent this to other file formats (broadcastable formats like MP3), if any of you would like to build up on this project please let me know, I would like to join if that's ok with you.

The improvements that are possible-

  1. Multicasting
  2. Video Transmission
  3. Addition of more file formats
  4. Implementation of a "broadcast codec"
  5. Peer-to-peer relay broadcasting (based on the concept of peer-to-peer file sharing)
  6. Playback from memory (i.e. no temporary disk storage)

You have problems?

  • Probably you started the programs in the wrong order.
  • OR The "c:\textnewsbroadcastfile.txt" file is not where it should be.
  • OR If you have big breaks in audio playback probably the MP3 file is a VBR one
  • OR The MediaServer program made an error in determining the bitrate of the file.
  • OR You have firewall enabled that might be blocking the UDP packets.

Can't think of anything else that might go wrong , so mail me if something terrible happens.

"If something can go wrong, it will go wrong!" - heard that somewhere.

That's all folks, bye bye.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
India India
I was doing some VC++ coding for 2 years while at college. But once i got out of college in 2005, went to work for an IT company in the enterprise solutions space.

Since 2005 working on TIBCO technologies. Couple of times i started working on some C# projects but never went about completing them.

You may also be interested in...

Comments and Discussions

QuestionYour program is very nice but its not working when i test it on lan Pin
Member 20806766-Jan-10 0:05
memberMember 20806766-Jan-10 0:05 
Ramanjit Arora30-Apr-08 9:42
memberRamanjit Arora30-Apr-08 9:42 
QuestionPossible On demad Straming........ Pin
Appupatel13-Nov-07 15:26
memberAppupatel13-Nov-07 15:26 
GeneralUdp send through internet problem [modified] Pin
shahrul6s23-Oct-07 18:57
membershahrul6s23-Oct-07 18:57 
QuestionCan it be modified as a Chat Conferencing? Pin
tempsh22-Aug-07 0:03
membertempsh22-Aug-07 0:03 
NewsOpenSource Audio library and Server Shoutcast Pin
DAXweb_IT31-Jul-07 7:42
memberDAXweb_IT31-Jul-07 7:42 
GeneralComplete Project Report Pin
loneferret14-Jul-07 3:30
memberloneferret14-Jul-07 3:30 
Generalre video broadcasting Pin
fize22-Nov-06 3:04
memberfize22-Nov-06 3:04 
GeneralRe: re video broadcasting Pin
shoonya25-Nov-06 23:23
membershoonya25-Nov-06 23:23 
GeneralRe: re video broadcasting Pin
fize27-Nov-06 22:03
memberfize27-Nov-06 22:03 
GeneralGood Simple Code; KEEP Going Pin
RadioSource3310-Aug-06 21:01
memberRadioSource3310-Aug-06 21:01 
Generalhelp for project Pin
V.G21-Sep-05 9:51
memberV.G21-Sep-05 9:51 
GeneralRe: help for project Pin
shoonya23-Sep-05 2:47
sussshoonya23-Sep-05 2:47 
GeneralRe: help for project Pin
shoonya23-Sep-05 3:39
sussshoonya23-Sep-05 3:39 
GeneralWant email address and contact for project Pin
Anonymous11-Mar-05 5:27
sussAnonymous11-Mar-05 5:27 
Questionhow to test on LAN? Pin
spdl20011-Mar-05 7:18
memberspdl20011-Mar-05 7:18 
QuestionWhat's going on??? Pin
j_h_o_n26-Feb-05 5:41
memberj_h_o_n26-Feb-05 5:41 
Generalhey dear Pin
jai_19819723-Feb-05 5:26
memberjai_19819723-Feb-05 5:26 
GeneralRe: hey dear Pin
shoonya23-Feb-05 7:04
membershoonya23-Feb-05 7:04 
Questionhow to remove Errors.... Pin
Jaideep Deshmukh3-Feb-05 6:27
memberJaideep Deshmukh3-Feb-05 6:27 
AnswerRe: how to remove Errors.... Pin
shoonya12-Feb-05 10:47
membershoonya12-Feb-05 10:47 
GeneralRe: how to remove Errors.... Pin
Michael900022-Jan-08 10:51
memberMichael900022-Jan-08 10:51 
GeneralMediaserver_new crash Pin
spdl20013-Jan-05 5:47
memberspdl20013-Jan-05 5:47 
GeneralRe: Mediaserver_new crash Pin
shoonya3-Jan-05 6:56
membershoonya3-Jan-05 6:56 
GeneralVery cool. but... Pin
Jim Koornneef12-May-04 11:28
memberJim Koornneef12-May-04 11:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.170217.1 | Last Updated 11 May 2004
Article Copyright 2004 by shoonya
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid