473,394 Members | 2,002 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,394 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 1342
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

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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.