我最近决定创建一个应用程序来查看其他计算机的桌面,到目前为止我可以看到桌面,但它似乎只发送 1 个图像:?我在客户端使用 TCP 客户端和一些线程(查看桌面的那个)。当服务器发送图像后,它似乎被锁定并成为无响应的 客户端接收代码:
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 和网络流很陌生,非常感谢任何帮助,谢谢!