Using Sockets to connect to a Shoutcast server does not work

T

ThunderMusic

Hi,
I'm trying to develop a shoutcast client using .net framework. I thought
sockets were the thing to use, but now I'm not that sure anymore.

I create the socket object, connects it to the server using
MySocket.Connect(IPAddressObj, Port). After that, the MySocket object says
it's connected (even if I have no clue of this in my shoutcast log), so I
continue the process and send the request to get the stream "Get /
HTTP.........." and so on... But then after that, I should be waiting for
some data to come in, but I receive nothing. Am I missing something?

Thanks

ThunderMusic

Here is the code I use:

Dim MyStream As New Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp)
Dim HostIP As IPAddress
Dim MyEndPoint As IPEndPoint
Dim BytesReady As Integer
Dim InBuf() As Byte
Dim SendStream As New System.IO.MemoryStream
Dim SendStreamWriter As New System.IO.StreamWriter(SendStream)

HostIP = GetIPAddress("localhost")

If Not (HostIP Is Nothing) Then
MyEndPoint = New IPEndPoint(HostIP, 8000)
End If

Try
MyStream.Connect(MyEndPoint)
Catch ex As Exception
SW.WriteLine(Now & " Exception: " & ex.Message)
End Try

If MyStream.Connected Then
SendStreamWriter.Write("GET / HTTP/1.1" & vbCrLf _
& "Host: " & HostIP.ToString & vbCrLf _
& "Accept: */*" & vbCrLf _
& "Referer: localhost:8000/" & vbCrLf _
& "User-Agent: TestSockets" & vbCrLf _
& "Icy-MetaData:1" & vbCrLf & vbCrLf)

MyStream.Send(SendStream.ToArray, SendStream.ToArray.Length,
SocketFlags.None)

MustLoop = True
Do While MustLoop
BytesReady = MyStream.Available

If BytesReady > 0 Then

' IT NEVER GETS HERE!!! WHY???
ReDim InBuf(BytesReady - 1)

MyStream.Receive(InBuf, InBuf.Length, SocketFlags.None)

End If

Application.DoEvents()
Loop

MyStream.Shutdown(SocketShutdown.Both)
MyStream.Close()
 
T

ThunderMusic

ok, i fixed my problem, it was something about the stream writen with the
GET query... the StreamWriter wrote nothing at all, I changed it to a
BinaryWriter, then it wrote the string but with a preceding StringLength, so
I used the binarywriter but instead of writing the string directly I wrote
TheString.ToCharArray and it did the trick, the server gets the query as it
needs to and then sends the audio stream. It's fine now.

Thanks anyway

ThunderMusic
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top