• hacer varias conexiones ^[desktop viewer]^ vb.net

 #493122  por dijaving
 20 Dic 2017, 06:35
pues basicamente quiero elejir en una tabla donde salgan las ids de los servidor y con el click derecho arrancar el escritorio remoto.
aqui el codigo:

cliente:

Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Drawing
Imports System.Runtime.Serialization.Formatters.Binary
Dim client As New TcpClient
Dim nstream As NetworkStream
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 SendImage()
Dim bf As New BinaryFormatter
nstream = client.GetStream
bf.Serialize(nstream, Desktop())
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
Me.Hide()
Try
client.Connect("127.0.0.1", 8085)
Catch ex As Exception
' MsgBox("Failed to connect...")
End Try

If client.Connected Then
SendImage()
End If
End Sub

-------------------------------------------------------------------------------------

servidor:

Imports System.IO
Imports System.Net
Imports System.Net.Sockets
Imports System.Threading
Imports System.Drawing
Imports System.Runtime.Serialization.Formatters.Binary

Dim client As New TcpClient
Dim server As New TcpListener(8085)
Dim nstream As NetworkStream
Dim listening As New Thread(AddressOf Listen)
Dim getImage As New Thread(AddressOf receiveImage)

Private Sub receiveImage()
Dim bf As New BinaryFormatter
While client.Connected = True
nstream = client.GetStream
picturebox1.Image = bf.Deserialize(nstream)
End While
End Sub

Private Sub Listen()
While client.Connected = False
server.Start()
client = server.AcceptTcpClient
End While
getImage.Start()
End Sub

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
listening.Start()
end sub


-----------------------------------


eso es todo la fuente es
[ Debe registrarse para ver este enlace ]
alli esta mejor explicado.