How to make a Desktop viewer vb 2010~!

Heres your chance to share your own tutorials with the community. Just post them on here. If your lucky they may even be posted on the main site.
28 posts Page 1 of 3
User avatar
Proprogrammer
VIP - Donator
VIP - Donator
Posts: 415
Joined: Sun Oct 03, 2010 11:14 pm

First Make two projects! One for Client and One for Server.
Name them what ever you want.

Get to your client project.

Objects needed-
1 picturebox(mine is named picDesk)
2 textboxes for ports(first textbox is txtport and second one is txtport2
1 button(mine is named btnListen)

after that you will need to import these settings-
Code: Select all
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Net.Sockets
Imports System.Net
Imports System.Threading
Imports System.Runtime.Serialization.Formatters.Binary
after that make a new sub called New or just copy below .
Code: Select all
Public Sub New()
        InitializeComponent()
        CheckForIllegalCrossThreadCalls = False
    End Sub
Now for the listening main part to listen for the server.(put this below the New sub)
Code: Select all
Private listener As TcpListener
    Private imgListener As TcpListener
    Private client As TcpClient
    Private imgClient As TcpClient
    Private imageListenThread As Thread
    Private listenerThread As Thread
Make a new sub, or for the listening part, just copy below and paste below Private funtions.
Code: Select all
 Private Sub Listen()
        listener = New TcpListener(IPAddress.Any, Integer.Parse(txtport.Text))
        listener.Start()
        'Starts listening for connections.
        While True
            client = listener.AcceptTcpClient()
            'After it gets accepted, it breaks the loop since we don't need it anymore.
            Exit While
        End While
        lblConnected.Text = "Connected: " & client.Client.RemoteEndPoint.ToString()
        imageListenThread = New Thread(AddressOf imageListen)
        imageListenThread.Start()
    End Sub
This next code is for recieving constant images from the server and putting them onto the picturebox-
Code: Select all
Private Sub imageListen()
        imgListener = New TcpListener(IPAddress.Any, Integer.Parse(txtport2.Text))
        imgListener.Start()
        'Starts the imgListener.
        While True
            imgClient = imgListener.AcceptTcpClient()
            'Same like above.
            Exit While
        End While
        Dim formatter As New BinaryFormatter()
        While True
            'Starts the loop.
            Using stream As NetworkStream = imgClient.GetStream()
                'We're using the stream the image is serialized-
                'to.
                While True
                    'Gets the image and loops.
                    picDesk.Image = DirectCast(formatter.Deserialize(stream), Image)
                End While
            End Using
        End While
    End Sub
Now for the final part of making the Client, this is the button code, obviously it just starts subs, and private functions.
Code: Select all
 listenerThread = New Thread(AddressOf Listen)
        listenerThread.Start()
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


Now go to your server project.


Objects needed-

3 textboxes(textbox1 for me is for ip address and is named(txtIp) textbox2 for me is for the first port # i named it(txtport) and (txtport2 for the second one)

1button- mine is named btnConnect

that is all needed now for the coding part.

import these settings-
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Net.Sockets
Imports System.Runtime.Serialization.Formatters.Binary
Imports System.Threading


make sub named New() like in the client-
Code: Select all
Public Sub New()
        InitializeComponent()
    End Sub
after that we need to put in the private functions to make variables and so on.
Code: Select all
Private client As TcpClient
    Private imgSender As TcpClient
    Private senderThread As Thread
    Public Function CaptureDesktop() 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
Now make a sub called Send().
Code: Select all
Private Sub Send()
        'You should know what this means from part 1, just in reverse.
        imgSender = New TcpClient(txtIp.Text, Integer.Parse(txtPort2.Text))
        Dim formatter As New BinaryFormatter()
        While True
            Using stream As NetworkStream = imgSender.GetStream()
                While True
                    formatter.Serialize(stream, CaptureDesktop())
                    'So it doesn't kill the cpu.
                    Thread.Sleep(1)
                End While
            End Using
        End While
    End Sub
Oh course this is how the program sends the screen.


Put this code in the button_click event
Code: Select all
Try
            client = New TcpClient(txtIp.Text, Integer.Parse(txtPort.Text))
            senderThread = New Thread(AddressOf Send)
            senderThread.Start()
        Catch ex As Exception
            'If it can't connect.
            MessageBox.Show(ex.Message) ' telling if it cant get to the client.
        End Try

That is how to make a Desktop viewer, thanks for reading!
------------------------------------------------------------------------------
Proprogrammer, not just a Programmer.
User avatar
upperdrag
Excellent Poster
Excellent Poster
Posts: 321
Joined: Fri Mar 12, 2010 12:05 pm

i dont get what does it do...
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Explain what it really does... You know Desktop Viewer doesn't explains much!
Image
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

This is like remote control software, only you can just view the screen.

You don't need to have listener.AcceptTcpClient() in a while loop as the thread is blocked by this function already.
User avatar
Proprogrammer
VIP - Donator
VIP - Donator
Posts: 415
Joined: Sun Oct 03, 2010 11:14 pm

oh thanks mandai! Yeah this is like the application Team Viewer kinda.
------------------------------------------------------------------------------
Proprogrammer, not just a Programmer.
User avatar
upperdrag
Excellent Poster
Excellent Poster
Posts: 321
Joined: Fri Mar 12, 2010 12:05 pm

so how do u use it.. ? never used team viewer before, infact lol never heard of it
User avatar
Usman55
VIP - Site Partner
VIP - Site Partner
Posts: 2821
Joined: Thu Dec 24, 2009 7:52 pm

Now I know it, So all this software does is that it displays another computer's screen on my computer!
Image
User avatar
Proprogrammer
VIP - Donator
VIP - Donator
Posts: 415
Joined: Sun Oct 03, 2010 11:14 pm

Yeah pretty cool though for something if you want to give someone a tutorial! With Exceptionally Great QUALITY!
------------------------------------------------------------------------------
Proprogrammer, not just a Programmer.
User avatar
Skillful
Skillful Coders
Skillful Coders
Posts: 969
Joined: Tue Nov 16, 2010 10:07 am

Well this looks nice. Will try it out later!!!
Instead of LOL use this -
LSIBMHBIWFETALOL

Which means -
Laughing silently in between my head because it wasn't funny enough to actually laugh out loud!
User avatar
MrAksel
C# Coder
C# Coder
Posts: 1758
Joined: Fri Mar 26, 2010 12:27 pm

So we just type in the port and we can speak and send images to each other?
In that case use port 150! So all can talk together.
Err, what IP should i type in? My?
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;


Over 30 projects with source code!
Please give reputation to helpful members!

Image
Image
28 posts Page 1 of 3
Return to “Tutorials”