Hi guys,
I am trying to make a remote access tool where a client computer can be monitored from a server computer.
For getting the client's computer desktop view, my programme take screen shots, save the file and send the
file to remote server computer. Here is the main code for the client-
Private Sub Live_pc()
Dim cmnd As String
Dim fs As FileStream
Dim flag As Boolean = True
Dim b As Bitmap = New Bitmap(My.Computer.Screen.Bounds.Width, My.Computer.Screen.Bounds.Height, Imaging.PixelFormat.Format32bppArgb)
Dim gfx As Graphics = Graphics.FromImage(b)
Dim filesize As Int64
Dim buffer() As Byte
Do
cmnd = bReader.ReadString()
Select Case cmnd
Case "Auto_Capture"
While flag
gfx.CopyFromScreen(My.Computer.Screen.Bounds.X, My.Computer.Screen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy)
b.Save("temp.xxx", Imaging.ImageFormat.Jpeg)
fs = File.OpenRead("temp.xxx")
ReDim buffer(fs.Length - 1)
filesize = fs.Length
fs.Read(buffer, 0, fs.Length)
bWriter.Write(filesize)
bWriter.Write(buffer, 0, fs.Length)
fs.Close()
flag = bReader.ReadBoolean
Threading.Thread.Sleep(30)
End While
Case "Stop_Auto_Capture"
Case "exit"
b.Dispose()
fs.Dispose()
gfx.Dispose()
Array.Clear(buffer, 0, buffer.Length)
Exit Do
End Select
Loop
End Sub
and the code for server which receive files-
Imports System.IO
Imports System.Net
Imports System.Text
Imports System.Drawing
Imports System.Threading
Imports System.Net.Sockets
Public Class frmLivePC
Private tcpclient As New TcpClient
Private BR As BinaryReader
Private BW As BinaryWriter
Private CaptureFlag As Boolean
Private Sub frmLivePC_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
BW.Write("exit")
End Sub
Public Sub New(ByVal client As TcpClient)
InitializeComponent()
tcpclient = client
BR = New BinaryReader(tcpclient.GetStream())
BW = New BinaryWriter(tcpclient.GetStream())
End Sub
Private Sub btnStart_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStart.Click
BW.Write("Auto_Capture")
CaptureFlag = True
btnStart.Enabled = False
btnStop.Enabled = True
Dim AutoCapturingThread As New Thread(AddressOf AutoCapture)
AutoCapturingThread.Start()
End Sub
Private Sub AutoCapture()
While CaptureFlag
Dim fs As FileStream
Dim filesize As Int64
filesize = BR.ReadInt64
Dim BUFFER_SIZE As Int32 = 4096
Dim BUFFER(BUFFER_SIZE - 1) As Byte
Dim byteread As Integer
fs = File.Create("temp.jpg")
While filesize
If filesize < BUFFER_SIZE Then BUFFER_SIZE = filesize
byteread = BR.Read(BUFFER, 0, BUFFER_SIZE)
fs.Write(BUFFER, 0, byteread)
filesize -= byteread
End While
fs.Close()
PictureBox.ImageLocation = "temp.jpg"
BW.Write(CaptureFlag)
End While
End Sub
Private Sub btnStop_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnStop.Click
CaptureFlag = False
BW.Write(CaptureFlag)
End Sub
End Class
I'm only providing the main part of the code. An active TCP connection is already made between server and client,
and the client starts the Live_pc() sub as the server starts frmLivePc Form. Now, my programme woks fine but having
some performance issue. Most of the times it hangs or the frames
are shown at a slow rate. I know i can get better performance if
i use UDP instead of TCP. But the problem is that the jpg files are around 110-140kb and i cant send these through
UDP. Using "UDPClient.send" method gives me a error telling that tthe datagram is too big to send over network.
Now i would like you to help me here. How can i get better performance? Is there any modification required or
do i have to use UDP and if so how would i do that? And i have a second question- the thing i'm trying to do here,
can it be done by forwarding the video memory of client's computer in the network? Some code about this would
be very helpfull. Thanks in advance :)