我最近决定创建一个应用程序来查看其他计算机桌面,OS很远,我可以看到桌面,但似乎只发送1个图像:?我正在使用TCP客户端和客户端(查看桌面的一个)线程。当服务器发送图像时,它似乎会锁定并变得无repsonsive客户端接收代码:
Private Sub check()
If sock.Connected = True Then
sock.SendTimeout = 5000
Try
Application.DoEvents()
Dim nstream As NetworkStream
Dim bf As New BinaryFormatter
nstream = sock.GetStream
PictureBox1.Image = Nothing
PictureBox1.Image = bf.Deserialize(nstream)
If nstream.DataAvailable = True Then
MsgBox(nstream)
End If
Catch ex As Exception
check()
End Try
End If
End Sub
,然后这是发送它的代码发送代码:
Public Function Desktop() As Image
Dim bounds As Rectangle = Nothing
Dim screenshot As System.Drawing.Bitmap = Nothing
Dim graph As Graphics = Nothing
bounds = Screen.PrimaryScreen.Bounds
screenshot = New Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
graph = Graphics.FromImage(screenshot)
graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
Return screenshot
End Function
Private Sub SendDesk()
If sock.Connected = True Then
Try
Dim nstream As NetworkStream
Dim bf As New BinaryFormatter
nstream = sock.GetStream
bf.Serialize(nstream, Desktop())
Catch ex As Exception
End Try
End If
End Sub
我已经在vb.net中编码了一段时间(基本内容,一些http的东西),但我是TCP和网络流的新手,任何帮助都非常重视,谢谢!
您需要重复图像发送过程...
While sock.Connected = True
Try
Dim nstream As NetworkStream
Dim bf As New BinaryFormatter
nstream = sock.GetStream
bf.Serialize(nstream, Desktop())
Catch ex As Exception
End Try
End While