byte Array To File Stream

G

Gigi

Hello,

I have a byte array and i must send(to blocks) to remote class
In the remote class i write a file stream......

How?


In my sample i send stream...

Code CLIENT:

FSource = New FileStream("c:\test.tif", FileMode.Open)
While FSource.Position < FSource.Length - 1
Call RemoteObject.WriteStream(FSource)
End While

Code SERVER:

Public Sub WriteStream(ByVal SourceStream As Stream)
Dim FOutput As FileStream

If Not File.Exists("c:\testremote.tif") Then
FOutput = New FileStream("c:\testremote.tif", FileMode.CreateNew,
FileAccess.ReadWrite)
Else
FOutput = New FileStream("c:\testremote.tif", FileMode.Append,
FileAccess.Write)
End If

Dim BWriter As BinaryWriter = New BinaryWriter(FOutput)
Dim i As Integer
Dim intBytesRead As Integer
Const intSize As Integer = 4096
Dim bytes(intSize) As Byte
intBytesRead = SourceStream.Read(bytes, 0, intSize)
BWriter.Write(bytes, 0, intBytesRead)
BWriter.Close()
FOutput.Close()
End Sub
 
H

Helge Jensen

Gigi said:
Hello,

I have a byte array and i must send(to blocks) to remote class
In the remote class i write a file stream......


How?

Are you just trying to write to a remote strem? Why dont you simply use
the "Read" and "Write" methods on the Stream with the data you wish to
write. whether it is remote or not should not matter.

remote.Write(bytes, 0, bytes.Length);

If you are trying to pass a stream to a remote class, you can "just do it":

public class RemoteThingy {
void f(Stream s) {
using ( TextWriter w = new StreamWriter(s) )
w.WriteLine("Hello Remote!");
s.Flush();
}
}

public class Client {
RemoteThingy remote = ...; // obtain remote instance
using ( Stream s = new FileStream("mytest.txt")
remote.f(s);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top