[2005] File will not send without Messagebox being displayed.
in the server code, if I take out the MsgBox(FileReader.BaseStream.Length) the client freezes, and the filesize of the transfered file is less then the complete file size. Line 10
here is the server sub
vb Code:
Private Sub SendAFile(ByVal FileName As String, ByVal WhichClient As Integer)
'file path C:\Documents and Settings\Owner\Desktop\Ya Ali - Ringtone.mp3
Re: [2005] File will not send without Messagebox being displayed.
If this helps, here is the entire Server, and Client project as it is right now.
I've tried everything I know, and could think of.
The only thing I could guess could have anything to do with it is...
maybe it needs a wait, or read, or something after the sendmessage command? Or maybe it needs a .flush? I am lost. I know that I don't understand the stream enough to debug what is going wrong.
I write 8 bytes to a stream with a buffer of 8096 or something in size. then I read on the other end 8 bytes. and it does that till the end.
Maybe I need to put a wait, in the loop? if mydatastream.canwrite=false then
wait for a mili second? I dunno. Anyone that has any guesses i'm willing to try them.
Please RATE posts, click the RATE button to the left under the Users Name.
Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.
Re: [2005] File will not send without Messagebox being displayed.
I downloaded your source and will look at it soon...
have you considered using UDP?, apparently it is unreliable and sometimes packets dont make it to their destination, also it is unordered (meaning packet 1 may be received before packet 2 but this is easily taken care of if you send an object which will hold order detail along with the data), one other bad point with UDP is that there is no way of telling if the packet is even received and another bad point is that a message can be received more than once.
It does have some good points thaugh, like bandwidth for one example, but in my eyes performance is nothing without reliability (who wants an app that will send the wrong message 10 times faster).Its just easier to work with, but nobody seems to use it?
Re: [2005] File will not send without Messagebox being displayed.
Ok, I got it to not hang, but now it's sending 12 extra bytes????
file size to start with is 377,106 bytes.
file size at the end is 377,118 bytes.
377,106 divided by 32k is 11.50836. Maybe i'm adding 1 extra byte each time I write or read or something?
Also, I just played the song file, its all screwed up, it loops through about 3-5seconds the entire 47 seconds of the song.
(EDIT)
If I put a messagebox just after line 35 in the client, during the last loop the client hangs, and the file does not get completed. Though if I remove this, it does get completed, but with 12 extra bytes, and with the file being screwed up.
(Edit 2)
I set the receive buffer size at 64k, and the send buffer size at 64k, to make sure I wasn't exceeding those somehow. File ends up being shorter now, and client hangs, also with clicks in MP3 song, so extra bytes are still getting in there.
Here is the server, and client code as it is now.
--SERVER--
vb Code:
Private Sub SendAFile(ByVal FileName As String, ByVal WhichClient As Integer)
'file path C:\Documents and Settings\Owner\Desktop\Ya Ali - Ringtone.mp3
Re: [2005] File will not send without Messagebox being displayed.
Well, I just tried a .bmp file, to see if I could visually see the changes, looks like it distorts the contents of the file so much, the .bmp can't be displayed.
I'm fresh out of ideas. I'm stuck. Please, anyone that has an option, or idea, no matter how small, remote, or unlikely, please post.
When using binarywriter.write(Byte() as bytearray, start, amountofdata)
the following code doesn't work.
Filewriter.Write(MyBytes, MyFileInfo.BytesReceived, LastBytes)
I get the error message:
Code:
offset and length were out of bounds for the array or count is greater
than the number of elements from index to the end of the source collection.
(EDIT)
Ok I figured out the above, but it doesn't fix the fact the file ends up competely screwed up.
Filewriter.Write(MyBytes, 0, LastBytes)
Last edited by rack; Jul 29th, 2007 at 05:44 PM.
Please RATE posts, click the RATE button to the left under the Users Name.
Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.
Re: [2005] File will not send without Messagebox being displayed.
It has to be something with the networkstream, or the way i'm writing to it, or reading from it.
I made a Binaryreader / writer application. Used the Filestream object also, and the file turned out exact duplicate.
Going to give up for now, and look back at this later.
(EDIT)
Ok, I can't give up my mind won't let me
Here is something from the help files, Does this have anything to do with my problems?
The ReceiveBufferSize property gets or sets the number of bytes that you are expecting to store in the receive buffer for each read operation. This property actually manipulates the network buffer space allocated for receiving incoming data.
Your network buffer should be at least as large as your application buffer to ensure that the desired data will be available when you call the NetworkStream.Read method. Use the ReceiveBufferSize property to set this size. If your application will be receiving bulk data, you should pass the Read method a very large application buffer.
If the network buffer is smaller than the amount of data you request in the Read method, you will not be able to retrieve the desired amount of data in one read operation. This incurs the overhead of additional calls to the Read method.
(/Edit)
(edit 2)
Ok, I wonder if I have to change the way i'm thinking. Currently I'm thinking, the server sends 32k, the client gets 32k. So they read like that. Maybe I have to set it up so that if say only 12k gets sent, the client knows to read 12k. I dunno i'm grabbing at strings now...
vb Code:
Imports system.io
Public Class Form1
Private Sub SendAFile(ByVal FileName As String, ByVal WhichClient As Integer)
'file path C:\Documents and Settings\Owner\Desktop\Ya Ali - Ringtone.mp3
Dim FileReader As IO.BinaryReader
Dim Fs As IO.FileStream
Dim Filewriter As IO.BinaryWriter
Dim FsW As IO.FileStream
FsW = New IO.FileStream(Application.StartupPath & "\Jeremytest.mp3", FileMode.CreateNew)
Re: [2005] File will not send without Messagebox being displayed.
Try this.
First make a class that has atleast a bytes property (may need more)
Code:
<Serializable()>Public class FileToSend
Private Bytes() as byte
Property Bytes
Get
Set
End Property
Public Sub AddFile(byval path as string)
'Serialize file into memory stream to add to bytes
End Sub
Public Sub SaveFile(byval path as string)
'Deserialize file and save to disc
End Sub
End Sub
Then serialize and send this object. Encapsulating the file inside an object may preserve the contents a bit better, If you dont know how to serialize and deserialize the file into a byte array using a memory stream I have an example , that you can find in another post from a few weeks ago, or I could reupload it tommorow
Re: [2005] File will not send without Messagebox being displayed.
I searched google, I searched Microsofts online help, there 101 source code, the MSDN Help files for the different functions, Binarywriter, BinaryReader, Filestream, Networkstream. I searched VBForums. I've read a lot of articles about what streams are. I've read a lot of posts about people wanting to create chat programs. I have yet to find source code for a working file transfer in .net (not using winsock control). I know that the problem I am having has to do with the networkstream, and my incomplete understanding of it. Because I wrote a program that reads from a file, into a filestream then into a binaryreader, it writes the data it gets into a byte array, then it writes the byte array into a binarywriter that writes that data into a filestream to a new file. I am going to sleep. Maybe my sub-consious will figure something out.
Please RATE posts, click the RATE button to the left under the Users Name.
Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.
Re: [2005] File will not send without Messagebox being displayed.
Last attempt, Bump.
Tomorrow if I don't get an answer, I'll try searching for a book. If I figure it out, i'll post the code, and the answer. Thanks for all the help so far, and for any help that may get posted tonight while I sleep.
Please RATE posts, click the RATE button to the left under the Users Name.
Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.