[icecast] Protocol

Oddsock oddsock at oddsock.org
Thu May 3 13:37:39 UTC 2001



Here is my code which shows the ICY protocol in action...please, no 
comments on the code, I know it's ugly (and it's win32)... :)

key thing to note is for Shoutcast, there are 2 socket connections needed, 
but only 1 for Icecast.

also, I can use this same logic to connect to a Icecast2 server (gOggFlag) 
as well....

oddsock

int connectToServer()
{
         int                     s_socket = 0;
         char            buffer[1024] = "";
         char    contentString[1024] = "";

         int             PubServ = 0;

         if (!strcmp(gPubServ, "TRUE")) {
                 PubServ = 1;
         }
         char    brate[25] = "";
         if (!strcmp(gOggFlag, "1")) {
                 sprintf(brate, "%s", gOggBitrateSplit);
         }
         else {
                 sprintf(brate, "%d", gLAMEOptions.brate);
         }

         gSCFlag = 0;
         dataChannel.initWinsockLib();

         SetDlgItemText(gHwnd, IDC_STATUS, "Connecting...");

         if ((!strcmp(gOggFlag, "1")) || (gIcecastFlag)) {
                 gSCSocket = dataChannel.DoSocketConnect(gServer, atoi(gPort));
         }
         else {
                 gSCSocket = dataChannel.DoSocketConnect(gServer, 
atoi(gPort)+1);
         }

         if (gSCSocket == -1) {
//              MessageBox(NULL, "Cannot connect to server", "Error", MB_OK);
                 SetDlgItemText(gHwnd, IDC_CONNECT, "Connect");
                 SetDlgItemText(gHwnd, IDC_STATUS, "Connect Failed...");
                 return -1;
         }
         int pswdok = 1;

         SetDlgItemText(gHwnd, IDC_STATUS, "Connected...");
         if ((!strcmp(gOggFlag, "1")) || (gIcecastFlag)) {
                 if (!strcmp(gOggFlag, "1")) {
                         sprintf(contentString, "SOURCE %s 
ICE/1.0\nice-password: %s\nice-name: %s\nice-url: %s\nice-genre: 
%s\nice-bitrate: %s\nice-public: %d\nice-description: %s\n\n", gMountpoint, 
gPassword, gServDesc, gServURL, gServGenre, brate, PubServ, gServDesc);
                 }
                 if (gIcecastFlag) {
                         sprintf(contentString, "SOURCE %s 
%s\nx-audiocast-name: %s\nx-audiocast-url: %s\nx-audiocast-genre: 
%s\nx-audiocast-bitrate: %s\nx-audiocast-public: 
%d\nx-audiocast-description: %s\n\n", gPassword,gMountpoint, gServDesc, 
gServURL, gServGenre, brate, PubServ, gServDesc);
                 }

         }
         else {

                         send(gSCSocket, gPassword, strlen(gPassword), NULL);
                         send(gSCSocket, "\r\n", strlen("\r\n"), NULL);

                         recv(gSCSocket, buffer, sizeof(buffer), NULL);
                         if (!strncmp(buffer, "OK", strlen("OK"))) {
                                 if (!strncmp(buffer, "OK2", strlen("OK2"))) {
                                         gSCFlag = 1;
                                 }
                                 else {
                                         gSCFlag = 0;
                                 }
                                 SetDlgItemText(gHwnd, IDC_STATUS, 
"Password OK...");
                         }
                         else {
                                 SetDlgItemText(gHwnd, IDC_STATUS, 
"Password Failed...");
                                 closesocket(gSCSocket);
                                 return -1;
                         }
                         sprintf(contentString, 
"icy-name:%s\r\nicy-genre:%s\r\nicy-url:%s\r\nicy-pub: 
%d\r\nicy-br:%s\r\n\r\n", gServDesc,gServGenre,gServURL, PubServ,brate);
         }

         send(gSCSocket, contentString, strlen(contentString), NULL);
         if (gIcecastFlag) {
                         recv(gSCSocket, buffer, sizeof(buffer), NULL);
                         if (!strncmp(buffer, "OK", strlen("OK"))) {
                                 if (!strncmp(buffer, "OK2", strlen("OK2"))) {
                                         gSCFlag = 1;
                                 }
                                 else {
                                         gSCFlag = 0;
                                 }
                                 SetDlgItemText(gHwnd, IDC_STATUS, 
"Password OK...");
                         }
                         else {
                                 SetDlgItemText(gHwnd, IDC_STATUS, 
"Password Failed...");
                                 closesocket(gSCSocket);
                                 return -1;
                         }
         }

         if (gSCFlag) {
                 sprintf(contentString, "GET /index.html 
HTTP/1.0\r\nUser-Agent: (Mozilla Compatible)\r\n\r\n");
                 gSCSocketControl = controlChannel.DoSocketConnect(gServer, 
atoi(gPort));
                 if (gSCSocketControl != -1) {
                         send(gSCSocketControl, contentString, 
strlen(contentString), NULL);
                         closesocket(gSCSocketControl);
                         updateSongTitle();
                 }
                 else {
//                              MessageBox(NULL, "Cannot connect to 
server", "Error", MB_OK);
                 }
         }

}

At 08:33 AM 5/3/2001, you wrote:
>jaromil,
>
> > >
> > > wanted to ask again if someone has some online documentation on the
> > > icecast (or shoutcast) protocol at the socket/data level.
> >
> > have a look into MuSE/libmpeg/httpinput.cc (http://muse.dyne.org)
> > i hope that code can help you figuring out
> >
>
>No actually not. It just makes the connection to the shoutcast/icecast
>server. I've gotten this far.
>
> > i also suggest you to use use libmpeg by Woo-jae Jung as a mp3 decoder 
> library, it's LGPL and for
> > me worked really fine with few modifications (misses just buffering 
> which would be good to
> > implement)
>
>I am using xaudio.
>
> >
> > btw congratulations for your libbgrab, i enjoy your code :)
>
>Thanks. I haven't worked on it for a while due to lack of time ...
>
>Ciao
>Andreas
>
>--- >8 ----
>List archives:  http://www.xiph.org/archives/
>icecast project homepage: http://www.icecast.org/
>To unsubscribe from this list, send a message to 'icecast-request at xiph.org'
>containing only the word 'unsubscribe' in the body.  No subject is needed.
>Unsubscribe messages sent to the list will be ignored/filtered.

--- >8 ----
List archives:  http://www.xiph.org/archives/
icecast project homepage: http://www.icecast.org/
To unsubscribe from this list, send a message to 'icecast-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Icecast mailing list