I'm trying to stream media to mediaplayer via a System.Net.Sockets.Socket, and I've found it difficult to do, when a file is sent in chunks. It works fine when files are sent in one piece, but when they are splitted up in packets of for instance 8192 bytes, the mediaplayer closes the connection after the first packet.

I've even tryed to add a http response header, but that doesn't seem to work either, so what can I do

Re: Visual Basic General Streaming media to mediaplayer via HTTP

Bruno Yu - MSFT


You can broadcast a stream by pushing it to a Windows Media server, which is useful when you want to initiate the connection from the encoding application. This method is also a way to broadcast a stream when a firewall separates the computers hosting an encoding application and a Windows Media server.

When pushing a stream to a Windows Media server, you need to know the following:

  • The name of the Windows Media server. This can be an alias, a fully qualified domain name, or an IP address.
  • The name of a new or existing publishing point.
  • Optionally, the name of an existing publishing point from which to use settings. For example, on the Windows Media server, you can configure a publishing point with the settings you would like to use each time you push a stream, and then you can use that publishing point as a template.

HTTP must be enabled on the Windows Media server:

  • On the Windows Media server, in the console tree, click the server that you want to use for this stream.
  • In the details pane, click the Properties tab.
  • In Category, click Control protocol.
  • Enable the WMS HTTP Server Control Protocol plug-in.

The following code snippet shows how to set up a multicast broadcast using IWMEncPushDistribution.

Code Block

' Create a WMEncoder object.

Dim Encoder As WMEncoder

Set Encoder = New WMEncoder

' Configure the encoding session including the input sources and profile.

' Create a push distribution object.

Dim PushDist As IWMEncPushDistribution

Set PushDist = Encoder.Broadcast

' Declare variables.

Dim sServerName As String

Dim sPubPoint As String

Dim sPubTemplate As String

Dim sMyNSCFile As String

Dim sMyNSCURL As String

Dim sMyASXFile As String

Dim sBrdcstInfo As String

' Provide values for the following variables.








' Specify the server name, publishing point, an existing publishing point,

' and then generate an NSC file and announcement file.

PushDist.ServerName = sServerName

PushDist.PublishingPoint = sPubPoint

PushDist.Template = sPubTemplate

' Specify whether to destroy the publishing point.

PushDist.AutoRemovePublishingPoint = True

' Initialize the encoding session.

Encoder.PrepareToEncode True

' Generate the announcement file.

PushDist.GenerateMulticastInfoFile sMyNSCFile

PushDist.GenerateAnnouncementFile sMyNSCURL, sMyASXFile

' Start encoding.


Hope that can help you.

Re: Visual Basic General Streaming media to mediaplayer via HTTP


I wanted to avoid using the WME, which is why I opted to use a sort of http server. I have figured it out now, and here's the answer:

Instead of using the basic socket for the send operation, I create a TcpClient with client property set to the connected socket. From the TcpClient, I send a http-header and the file via a netstream, thus streaming to the mediaplayer.

Code Block


Dim Client As New TcpClient

Client.Client = Socket

Dim NS As NetStream = Client.GetStream

'Send http-header, and the files bytes, seperated in chunks according to Client.Sendbuffersize

Re: Visual Basic General Streaming media to mediaplayer via HTTP

Bruno Yu - MSFT


Thanks very much for your follow up with the solution. I believe it will help more people on this kind of problems. Thanks again for your question and replies.

Re: Visual Basic General Streaming media to mediaplayer via HTTP


To elaborate on the http-headers, a fitting header for mp3 files would be:

Code Block

HTTP 1.1 200 OK

Date: Mon, 23 May 2005 22:38:34 GMT
Server: MyServer 1.1

Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT
Content-Type: audio/mpeg3

Content-Length: 7735732

Accept-Ranges: bytes

- Each line is seperated by a linefeed (vbCrLF-), and a linefeed is added between header and content data.

- Date formats may be a longdate format (Date.Now()).

- A list of mime-types (Content-type) is available here:

- The correct approach is, to send the header followed by a seperating linefeed and the content data.