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()
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()