Re: Obtuze - A Neural Network for OCR
my problems is im not being able to repeatedly send the images ....as it should appear as a video at the picbox at client end....
Re: Remote Desktop viewer
Posts moved from an unrelated topic in the 'Project Communication Area' forum.
Next time you have a question, please start a new thread rather than posting to somebody elses (especially one that is a completely different topic).
Re: Remote Desktop viewer
Thanks Si :thumb:
prashantRawal, I for one tend not to download Zip files and hunt for the relevant parts of your code that could cause your problems.
Explain what your problem is in detail, and post relevant parts of the code.
Re: Remote Desktop viewer
Extremely sorry guys.......didn't want to break rules of yours....but im a new bee at the vbforum and even to the vb.net.......was in a hurry.....sorry once again....:confused:;)
Re: Remote Desktop viewer
Dont worry about it prashantRawal, you haven't broken any rules. Could you post the relevant code and explain your problem in detail?
Re: Remote Desktop viewer
Hi,
I am implementing a concept like this...
- Once a connection with the server machine is established, client machine sends a request saying "Start Screening", thats is start sending image files if the server machine screen....
client side--
Code:
Private Sub cmdConnect_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles cmdConnect.Click
Try
client = New tcpConnection(txtServer.Text, PORT_NUM)
Catch ex As Exception
MessageBox.Show(Me, ex.Message, "Network Error", MessageBoxButtons.OK, _
MessageBoxIcon.Error)
Me.Dispose()
End Try
End Sub
Private Sub cmdGetPicture_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles cmdGetPicture.Click
'request a picture file from server
client.Send(Requests.PictureFile, "Start Screening")
End Sub
' send method
Public Sub Send(ByVal msgTag As Byte, ByVal strX As String)
'sends a string of max length PACKET_SIZE
SyncLock client.GetStream
Dim writer As New StreamWriter(client.GetStream)
'Notify other end that a string block is coming
writer.Write(Chr(RequestTags.StringTransfer))
'Send user defined message byte
writer.Write(Chr(msgTag))
'Send the string
'MsgBox(strX)
writer.Write(strX)
'make sure all data gets sent now
writer.Flush()
End SyncLock
End Sub
'Data Received event ....what to do when image file comes
Private Sub client_DataReceived(ByVal Sender As tcpConnection, ByVal msgTag As Byte, _
ByVal mstream As System.IO.MemoryStream) Handles client.DataReceived
'This code is run in a seperate thread from the thread that started the form
'so we must either handle any control access in a special thread-safe way
'or ignore illegal cross thread calls
Select Case msgTag
Case Requests.PictureFile
'picture data, put into our local picturebox control
SetPicture(mstream)
End Select
End Sub
'setting the image in picture box
Private Sub SetPicture(ByVal mstream As System.IO.MemoryStream)
' Thread-safe way to access the picturebox
' This isn't really needed because we are ignoring illegal cross thread calls.
If Me.PictureBox1.InvokeRequired Then
Dim d As New SetPictureCallback(AddressOf SetPicture)
Me.Invoke(d, New Object() {mstream})
Else
PictureBox1.Image = Image.FromStream(mstream)
End If
End Sub
Re: Remote Desktop viewer
-And on server side on Request from the connected client, - image file which are created on server form load event in some directory of server machine, after capturing screen image and saving that image there - sent one by one ....as shown below
server side..
Code:
Private Sub frmServer_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'start listening on our port as soon as the form loads
listener = New clsListener(PORT_NUM, PACKET_SIZE)
thrd1 = New Thread(AddressOf listener.createFile)
thrd1.Start()
End Sub
'methods to create files
Private Function CapScreen() As Bitmap
Dim desktopBMP As Bitmap
Dim g As Graphics
Dim rect As Rectangle
desktopBMP = New Bitmap(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height)
g = Graphics.FromImage(desktopBMP)
g.CopyFromScreen(0, 0, 0, 0, New Size(System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width, System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height))
rect = New Rectangle(Cursor.Position.X - Cursor.Current.HotSpot.X, Cursor.Position.Y - Cursor.Current.HotSpot.Y, Cursor.Current.Size.Width, Cursor.Current.Size.Height)
Cursor.Current.Draw(g, rect)
Return desktopBMP
End Function
Public Sub createFile()
Dim j As Integer = 1
For i As Integer = j To 30 Step +1
Dim fnm As String = "D:\Temp\" & i & ".JPG"
Dim img As Bitmap
img = CapScreen()
img.Save(fnm, System.Drawing.Imaging.ImageFormat.Jpeg)
If i = 30 Then
i = j
End If
Next
End Sub
'On request received
Private Sub listener_StringReceived(ByVal Sender As tcpConnection, ByVal msgTag As Byte, _
ByVal message As String) Handles listener.StringReceived
'This is where the client will send us requests for file data using our
' predefined message tags
Debug.Print("String Received from Client: " & message)
Select Case msgTag
Case Requests.PictureFile
For i As Integer = 1 To 30
Sender.SendFile(msgTag, picDir & i & ".jpg")
If i = 30 Then
i = 1
End If
Next
End Select
End Sub
'sending files with SendFile method
Public Sub SendFile(ByVal msgTag As Byte, ByVal FilePath As String)
'max filesize is 2GB
Dim byteArray() As Byte
Dim fs As FileStream = New FileStream(FilePath, FileMode.Open, FileAccess.Read)
Dim r As New BinaryReader(fs)
SyncLock client.GetStream
Dim w As New BinaryWriter(client.GetStream)
'notify that file data is coming
w.Write(RequestTags.DataTransfer)
'send user-define message byte
w.Write(msgTag)
'send size of file
w.Write(CInt(fs.Length))
'Send the file data
Do
'read data from file
byteArray = r.ReadBytes(PACKET_SIZE)
'write data to Network Stream
w.Write(byteArray)
Loop While byteArray.Length = PACKET_SIZE
'make sure all data is sent
w.Flush()
End SyncLock
End Sub
I handle the infoemation transferred between Client and Server using following method on both sides
Code:
Private Sub ReceiveOneByte(ByVal ar As IAsyncResult)
'This is where the data is received. All data communications
'begin with a one-byte identifier that tells the class how to
'handle what is to follow.
Dim r As BinaryReader
Dim sreader As StreamReader
Dim mStream As MemoryStream
Dim lData As Int32
Dim readBuffer(PACKET_SIZE) As Byte
Dim StrBuffer(PACKET_SIZE) As Char
Dim passThroughByte As Byte
Dim nData As Integer
Dim lenData As Integer
SyncLock client.GetStream
'if error occurs here then socket has closed
Try
client.GetStream.EndRead(ar)
Catch
RaiseEvent Disconnect(Me)
Exit Sub
End Try
End SyncLock
'this is the instruction on how to handle the rest of the data to come.
Select Case readByte(0)
Case RequestTags.Connect
'sent from server to client informing client that a successful
'connection negotiation has been made and the connection now exists.
isConnected = True 'identifies this class as on the client end
RaiseEvent Connect(Me)
SyncLock client.GetStream
r = New BinaryReader(client.GetStream)
PACKET_SIZE = r.ReadInt16
'Continue the asynchronous read from the NetworkStream
Me.client.GetStream.BeginRead(readByte, 0, 1, AddressOf ReceiveOneByte, Nothing)
End SyncLock
Case RequestTags.Disconnect
'sent to either client or server
'propagated forward to Listener on server end
RaiseEvent Disconnect(Me)
Case RequestTags.DataTransfer
'a block of data is coming
'Format of this transaction is
' DataTransfer identifier byte
' Pass-Through Byte contains user defined data
' Length of data block (max size = 2,147,483,647 bytes)
SyncLock client.GetStream
r = New BinaryReader(client.GetStream)
'next we expect a pass-through byte
client.GetStream.Read(readByte, 0, 1)
passThroughByte = readByte(0)
'next expect length of data (Int32)
nData = r.ReadInt32
lenData = nData
'now comes the data, save it in a memory stream
mStream = New MemoryStream
While nData > 0
RaiseEvent TransferProgress(Me, passThroughByte, CSng(1.0 - nData / lenData))
lData = client.GetStream.Read(readBuffer, 0, PACKET_SIZE)
mStream.Write(readBuffer, 0, lData)
nData -= lData
End While
'Continue the asynchronous read from the NetworkStream
Me.client.GetStream.BeginRead(readByte, 0, 1, AddressOf ReceiveOneByte, Nothing)
End SyncLock
'once all data has arrived, pass it on to the end user as a stream
RaiseEvent DataReceived(Me, passThroughByte, mStream)
mStream.Dispose()
Case RequestTags.StringTransfer
'Here we receive the transfer of string data in a block
'not to exceed PACKET_SIZE in length.
SyncLock client.GetStream
sreader = New StreamReader(client.GetStream)
'next we expect a pass-through byte
client.GetStream.Read(readByte, 0, 1)
passThroughByte = readByte(0)
nData = sreader.Read(StrBuffer, 0, PACKET_SIZE)
End SyncLock
Dim strX As New String(StrBuffer, 0, nData)
'pass string on to end user
RaiseEvent StringReceived(Me, passThroughByte, strX)
SyncLock client.GetStream
'Continue the asynchronous read from the NetworkStream
Me.client.GetStream.BeginRead(readByte, 0, 1, AddressOf ReceiveOneByte, Nothing)
End SyncLock
Case RequestTags.ByteTransfer
'Here we receive a user-defined one-byte message
SyncLock client.GetStream
client.GetStream.Read(readByte, 0, 1)
End SyncLock
'pass byte on to end user
RaiseEvent MessageReceived(Me, readByte(0))
SyncLock client.GetStream
'Continue the asynchronous read from the NetworkStream
Me.client.GetStream.BeginRead(readByte, 0, 1, AddressOf ReceiveOneByte, Nothing)
End SyncLock
End Select
End Sub
Now after doing this....My problem is...I am receiving first image at client end and than nothing happens.....I need to receive the images frequently,and to make it look like a video is running on a picture box .....i've done this on single application but failed here to manage the co-ordination...
Tell me what I should do to resolve this ....and tell me if i have any misconception anywhere in my application.....
thanks in advance...
Re: Remote Desktop viewer
HI,,,,
can any one pls help me solve my problem.......?
Re: Remote Desktop viewer
there is one thing to be aware of: system network bandwidth. You are basically streaming uncompressed video here, and you will never get the speed necessary to make it look like a video. This is why the decent programs that do this compress the video before sending. This has its drawbacks as well though, namely processor usage of the host system.
Re: Remote Desktop viewer
hi...
first of all thanks for the reply....
Now i am not sending ready video but the images one by one....
so as u said tht its a bandwitnh problem then how can i solve it..?
Am i supposed to compress the images and than send it or something else...?
do reply..
thankls in advance....
Re: Remote Desktop viewer
pretty much yes. A shortcut would be to compare two captured images for changes and only send a new one in that case. Also i have seen programs that only send jpeg shots like that save bandwidth by disabling windows themes and shutting of wallpaper. Solid colors compress to a much smaller image.