Old 21st September 2012, 17:10   #1
Deleted 18
Guest
 
Posts: n/a
ShoutCast connect socket

Hi!
I write application in C++ to broadcasting on ShoutCast server and I have a problem with socket connect to ShoutCast server. How can I do it? I mean mainly the password authorization because I browsed sources applications a eg. streamTranscoderV3 to cut connect line, but the combination never seen sent password.

Thanks for help.
  Reply With Quote
Old 21st September 2012, 23:15   #2
jaromanda
Forum King
 
Join Date: Jun 2007
Location: Under the bridge
Posts: 2,290
for DNAS 2 : http://wiki.winamp.com/wiki/SHOUTcas...otocol_Details

for old DNAS .. streamtranscodervV3 (and all shoutcast v1 protocol sources) DO send a password - it's the very first thing sent after connection if my memory serves me correctly

"If you don't like DNAS, write your own damn system"

So I did
jaromanda is offline   Reply With Quote
Old 27th December 2012, 20:21   #3
henkdefries
Junior Member
 
Join Date: Dec 2012
Posts: 2
Hi all,

I am also writing a c++ application to broadcast to a shoutcast server, but don't know if i'm on the right track.
I want to send a MP3 or wave file to the shoutcast server, so it can broadcast it to winamp and/or itunes
I have my shoutcast server running in a terminal and i can visit the shoutcast website using http://myshoutcastserver:8000. I also can connect to the server, using the folowing code:
PHP Code:
const charmp3 "/Users/info/Projecten/C++/ShoutcastTool/10 Surreal State Of Enlightenment.mp3";
    
charserver "192.168.2.2";// Shoutcast Server IP
    
int port 8000// shoutcast server port

    
charbytes readFileBytes(mp3);// fopen to char* buffer
    
int sockfd socket(AF_INETSOCK_STREAM0);// Connect
    
    // Getting sockaddr
    
struct sockaddr_in addr;
    
addr.sin_family AF_INET;
    
addr.sin_port htons(port+1);// Port +1
    
addr.sin_addr.s_addr inet_addr(server);

    
connect(sockfd, (struct sockaddr *)&addrsizeof(addr));
            
    
    
// We are now connected
    
shoutcast_send_line(sockfd, (char*)"mypassword");// shoutcast password
    
    
char buf[256];
    
shoutcast_receive_line(sockfdbufsizeof(buf));
    if (
strncmp(buf"OK2"3) != 0)
    {
        
printf("Invalid password");
        return -
1;
    }
    
    
shoutcast_receive_line(sockfdbufsizeof(buf));
    
printf("Response: %s"buf);
    
    
shoutcast_send_line(sockfd, (char*)"icy-name: Server name");
    
shoutcast_send_line(sockfd, (char*)"icy-genre: Metal");
    
shoutcast_send_line(sockfd, (char*)"icy-url: http://www.my_url.nl");
    
shoutcast_send_line(sockfd, (char*)"icy-pub: 0");
    
shoutcast_send_line(sockfd, (char*)"icy-br: 192");
    
shoutcast_send_line(sockfd, (char*)"content-type: mp3");// or audio/mpeg
    
shoutcast_send_line(sockfd, (char*)"\n"); 
Could anyone point me out to the right direction? If i'm right, i need to use a MP3 encoder like LAME, but don't know why.
I tried to build the lame encoder on osx, but have some troubles compiling. Is there another way?
And, how do i send the stream? I came up with a possible method, but is this the right way to go?

PHP Code:
size_t chunksize 64;// The size of a package?!?!?
    
int mediasize sizeof bytes;
    
int parts ceil(mediasize/chunksize);
    
char mediabuf[chunksize];
    for (
int x 0partsx++)
    {
        
memcpy(mediabufbytes+(chunksize), chunksize);
        
send(sockfdmediabufchunksize0);
        
usleep(100);// Some timeout?!?!?!?!?!?!
    

Greetings,

Henk de Fries

ps. compiling on osx xcode

Last edited by henkdefries; 27th December 2012 at 20:29. Reason: PHP has better color coding than CODE, update
henkdefries is offline   Reply With Quote
Old 28th December 2012, 02:22   #4
SC_Hebbian
Junior Member
 
Join Date: Dec 2012
Posts: 3
Quote:
Originally Posted by henkdefries View Post
Could anyone point me out to the right direction? If i'm right, i need to use a MP3 encoder like LAME, but don't know why.
I tried to build the lame encoder on osx, but have some troubles compiling. Is there another way?
And, how do i send the stream? I came up with a possible method, but is this the right way to go?
Yes, use the MP3 encoder like LAME. It's quite easy to build such codes with LAME, check their example project in the frontend folder.
SC_Hebbian is offline   Reply With Quote
Old 28th December 2012, 20:55   #5
DrO
 
Join Date: Sep 2003
Posts: 27,873
the audio has to be MP3 encoded, sending the raw wav file will not work. as for what to do, you're best having a look at other projects which already do it (and provide code) like libshout or B.U.T.T.

-daz
DrO is offline   Reply With Quote
Old 4th January 2013, 13:41   #6
henkdefries
Junior Member
 
Join Date: Dec 2012
Posts: 2
Thank you for your response, but I don't think i fully understand.
My audio file is allready MP3. Do i need to encode/decode it to something else to upload? I read that shoutcast doesn't mind.
Butt uses the stream from the soundcard, and allready is a stream. But how do I make a stream from the MP3?

I included LAME in my application, but I only found out how to make mp3 from other formats.

Greetings,

Henk de Fries
henkdefries is offline   Reply With Quote
Old 4th January 2013, 21:22   #7
DrO
 
Join Date: Sep 2003
Posts: 27,873
you need to have the encoded MP3 frame data and then that is put in the packet which is sent to the DNAS from your source.

with the case of BUTT if it's sampling from line-in then it would be encoding to MP3 and then sending that.

if you're only doing MP3 files then you just need to implement / use a parser which will get you the frame data so you can then send it on. as such you wouldn't need to have LAME, that's only useful if you're taking PCM input and then want to create MP3 output (like the official Source DSP does).

-daz
DrO is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Shoutcast > Shoutcast Technical Support

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump