DalexL
Active member
- Joined
- Jul 3, 2010
- Messages
- 34
- Programming Experience
- 3-5
The entire project that I'm working with is located here (click the download link on the RIGHT side of the page, the files name is "Server.zip"), I'm sorry it's not onsite. I was unable to get the vbdotnetforums uploader to upload without errors. I really am.
This is a home made server thats hosts a server on port 80. To connect to the server just put "http://Localhost/" in you browsers address bar in case you didn't already know.
I'm currently able to send data from the "Site" folder to the browser, however, I'm currently having a problem sending non-text based files (Videos, Images, and other things of the sort). In fact, it errors attempting to send PNGs and Icons. It can send music and JPEGs but sends the text instead of the actual file. I was wondering if there was some kind of way to fix that. Explanations or tips would be appreciated.
Here is the function I think I've narrowed the problem down to:
The error I commonly receive is:
Of course, you can always see this for yourself in the actual file. I'm sorry I've uploaded it to another site. It's in a ZIP, feel fine to scan it if it makes you feel better.
Thanks!
This is a home made server thats hosts a server on port 80. To connect to the server just put "http://Localhost/" in you browsers address bar in case you didn't already know.
I'm currently able to send data from the "Site" folder to the browser, however, I'm currently having a problem sending non-text based files (Videos, Images, and other things of the sort). In fact, it errors attempting to send PNGs and Icons. It can send music and JPEGs but sends the text instead of the actual file. I was wondering if there was some kind of way to fix that. Explanations or tips would be appreciated.
Here is the function I think I've narrowed the problem down to:
VB.NET:
Private Sub SendPage(ByVal response As HttpListenerResponse, ByVal Location As String, Optional ByVal directory As Boolean = False)
With response
.ContentType = "text/html"
.ContentEncoding = Encoding.UTF8
If directory Then
.ContentLength64 = Location.Length
Else
.ContentLength64 = My.Computer.FileSystem.GetFileInfo(Location).Length
End If
Try
Using writer As New StreamWriter(.OutputStream)
With writer
If directory Then
.Write(Location)
Else
.Write(My.Computer.FileSystem.ReadAllText(Location.Replace("%20", " ")))
.Flush()
End If
End With
End Using
Catch ex As Exception
WriteMessage("Reply failed!")
Finally
.Close()
End Try
End With
End Sub
The error I commonly receive is:
System.InvalidOperationEception: Cannot close stream until all bytes are written.
at System.Ne.HttpResponseStream.Dispose(Bolean disposing)
at System.IO.Stream.Close()
at System.IO.StreamWriter.Dispose(Boolean disposing)
at System.IO.TetWriter.Dispose()
at Server.ServerClass.SendPage(HttpListenerResponse response, String Location, Boolean directory) in C:\Users\*******\Documents\Visual Studio 2008\Projects\Server\Server\ServerClass.vb:line 143
Of course, you can always see this for yourself in the actual file. I'm sorry I've uploaded it to another site. It's in a ZIP, feel fine to scan it if it makes you feel better.
Thanks!