Paul
You are getting the exception because the bytes as an array of 256 bytes. The data sent is only 130 bytes. So, when deserialize, you have junk bytes at the end causing the exception
Tu-Thac
----- Paul Fi wrote: ----
I have this client code
string server = "localhost"
int port = 8085
IPHostEntry hostent = Dns.Resolve(ser ver)
IPAddress hostadd = hostent.Address List[0]
IPEndPoint EPhost = new IPEndPoint(host add, port)
Socket soc = new Socke(AddressFa mily.InterNetwo rk
SocketType.Stre am,ProtocolType .Tcp)
soc.Connect(EPh ost)
ArrayList al = new ArrayList()
al.Add("hello")
al.Add("world!" )
MemoryStream ms = new MemoryStream()
BinaryFormatter bf = new BinaryFormatter ()
bf.Serialize(ms ,al)
Console.WriteLi ne("Length : " + ms.Length + "Pos : " + ms.Position)
ms.Position = 0
byte[] data = new byte[ms.Length]
int i = ms.Read(data,0, data.Length)
soc.Send(data,0 ,data.Length,So cketFlags.None)
Console.WriteLi ne("data is sent")
Console.ReadLin e()
and my server code
IPAddress ipAddress = Dns.Resolve("lo calhost").Addre ssList[0]
TcpListener server = new TcpListene(ipAd dress,8085)
server.Start()
Console.WriteLi ne("Server started listening")
while (true)
Socket s = server.AcceptSo cket()
byte[] bytes = new Byte[256]
s.Receive(bytes , 0, s.Available
SocketFlags.Non e)
MemoryStream ms = new MemoryStream(by tes)
BinaryFormatter bf = new BinaryFormatter ()
ms.Position = 0
object al = bf.Deserialize( ms)
s.Close()
so what my client is doing is serializing my arraylist object into
byte stream and sending the array of bytes over to the server proces
where the server will wrap the byte array with the same type of strea
used at the client side and then deserialzed into its original stat
which is arraylist type
But when deserializing at the server side im getting this error which
cant figure out
Exception : Binary stream does not contain a valid BinaryHeader,
possible causes, invalid stream or object version change betwee
serialization and deserialization
can any one help me here pl
*** Sent via Developersdex
http://www.developersdex.com **
Don't just participate in USENET...get rewarded for it