473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Using Sockets to connect to a Shoutcast server does not work

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()
Nov 27 '05 #1
1 2733
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

"ThunderMusic" <NO.danlat.at.hotmail.com.SPAM> a écrit dans le message de
news: %2****************@TK2MSFTNGP12.phx.gbl...
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()

Nov 27 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Nick Keighley | last post by:
I'm probably missing something rather obvious, but is there a known problem with getting a Python based socket program to communicate with a C based socket program? A simple echo server written in...
1
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for...
6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
18
by: Jen | last post by:
I'm using Microsoft's own VB.NET FTP Example: http://support.microsoft.com/default.aspx?scid=kb;en-us;832679 I can get the program to create directories, change directories, etc., but I can't...
2
by: http://www.visual-basic-data-mining.net/forum | last post by:
Say i have declare a module for connection and two buttons... one button has the method connect() and the other has the method disconnect().... how do i actually connect after i had disconnect...
1
by: ThunderMusic | last post by:
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...
0
by: den 2005 | last post by:
Hi everybody, I am still learning how sockets, TcpClient and TcpListener work, in order that both sides to send and receive data, both sides must have a socket or TcpListener and a TcpListener...
1
by: verge | last post by:
hello everyone! how's it going? like everyone in here im in need of some help and good friendship along the way...take a look at this: //MODIFIED SO IT DEALS WITH WINDOWS FTP USING ACTIVE...
6
by: 7stud | last post by:
My question pertains to this example: #!/usr/bin/env python import socket, sys, time host = sys.argv textport = sys.argv s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.