I've got this class
And I just added this FILECONTENT propertyCode:Public Class FSObject Private _FileString As String Public Property FileString As String Get Return _FileString End Get Set(ByVal value As String) _FileString = value End Set End Property Private _FileId As String Public Property FileId As String Get Return _FileId End Get Set(ByVal value As String) _FileId = value End Set End Property Private _FileIndex As String Public Property FileIndex As String Get Return _FileIndex End Get Set(ByVal value As String) _FileIndex = value End Set End PropertyImportant thing to note is the FILECONTENT property - it will be a huge byte array of the file contents.Code:Private _FileContent As Byte() Public Property FileContent As Byte() Get Return _FileContent End Get Set(ByVal value As Byte()) ReDim _FileContent(value.Length) _filecontent = value End Set End Property End Class
I create the object like this
Now in the CALLQUERY function I used to just send the filename - now I want to send the entire class object - since it has the file contents - to the receiving appCode:For Each file As String In files Dim MyThread As Thread ' simple new thread Dim newFS As FSObject = New FSObject() 'new FSObject which is a file object I made up ' used because i needed to keep the name and index matched so the callback function had something to work with newFS.FileString = file 'this is just the name of it newFS.FileIndex = FileList.Count 'this is the objects position in the array, so the callback function knows where it is Using fs As New FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read) length = fs.Length Dim buffer(length) As Byte length = fs.Read(buffer, 0, length) newFS.FileContent = buffer End Using FileList.Add(newFS) 'just adding NewFS to file List so work function knows about it and the draw function knows about it MyThread = New Thread(AddressOf CallQuery) 'Standard Thread Stuff, Giving it the address of a function which is the function that calls the HTTPApp MyThread.Start(newFS) 'And starting the thread. The newFS is an object the thread will pass to the called function - can only be one argument Next
Instead of sending SENDSTRING - I would like to send the entire FSOb object.Code:Private Sub CallQuery(ByVal FSOb As FSObject) Dim prefixes() As String = {"http://localhost:8080/HttpListener/"} Dim request As WebRequest = WebRequest.Create(prefixes(0)) request.Method = "POST" request.ContentType = "application/x-www-form-urlencoded" Dim bytes() As Byte Dim sendString As String = FSOb.FileString + "|" + FSOb.FileIndex bytes = System.Text.Encoding.ASCII.GetBytes(sendString) request.ContentLength = bytes.Length Try Dim outputstream As Stream = request.GetRequestStream() outputstream.Write(bytes, 0, bytes.Length) Dim response As WebResponse = request.GetResponse() Dim datastream As Stream = response.GetResponseStream() Dim reader As New StreamReader(datastream) Dim responseFromServer As String = reader.ReadToEnd() outputstream.Close() reader.Close() response.Close() AnswerBack(responseFromServer) 'calling the callback function with the response from the server 'As far as i understand this calls the AnswerBack function with the InvokeRequired set true and nothing else fance or weird. Catch ex As Exception MessageBox.Show(ex.Message, "GetRequestStream") End Try End Sub
Can I serialize this object and then make it materialize again in the receiving app??




Reply With Quote