JBTALKS.CC

标题: 跪求熟悉vb.net tcp connection的大大赐教~! [打印本页]

作者: A|v1n_alvin    时间: 2012-10-31 07:03 PM
标题: 跪求熟悉vb.net tcp connection的大大赐教~!
小弟我遇到一个问题,就是client send image to server 的问题,我是用tcp connection,因为还有send一些文字...
上网找了,有人说用UDP比较快,可是TCP 比较稳定不是?
这是我的coding
client sending的:
        Dim mStream As New System.IO.MemoryStream()
        Dim bits() As Byte
        img.Save(mStream, Imaging.ImageFormat.Jpeg)
        bits = mStream.GetBuffer

        netStream = clientSocket.GetStream
        netStream.Write(bits, 0, bits.Length)
        netStream.Flush()

这是server receive的:
         netStream = incomingClient.GetStream
         Dim bytesRead(CInt(incomingClient.ReceiveBufferSize)) As Byte
         netStream.Read(bytesRead, 0, CInt(incomingClient.ReceiveBufferSize))

         Dim img As Image
         Dim mStream As IO.MemoryStream = New IO.MemoryStream(bytesRead)
         img = Image.FromStream(mStream)

         PictureBox1.Image = img
         
我发现到从client send出去的byte length是130065,可是server receive到的byte length只有8192,为什么啊?
然后造成img = Image.FromStream(mStream) 出现error: parameter not valid

如果没错,应该是receive少了,结果不能解读...
请高手赐教~




欢迎光临 JBTALKS.CC (https://jbtalks.my/) Powered by Discuz! X2.5