VB Screen Sharing

I'd like to write a program that allows me to work on my PC from other PCs in our LAN, or over the internet. (a kind of screen sharing app). I think it would be fairly easy by sending compressed images over TCP to the guest, then having the guest sending input back to my PC.

So how do I:

  • Take a screenshot
  • Compress it to a small JPG
  • Send it over a TcpClient connection

Thanks in advance.




Answer this question

VB Screen Sharing

  • SharePointing

    Thanks for your speedy reply.

    At the client side how can I get the image and display it as the background image on a form

    P.S. Thanks for all the help I've received from you in the past. It is all much appreciated.



  • Pavan Contractor

    no worries Robin, I'm glad I could be of assistance to you, and its always a pleasure!

    in regards to recieving it and doing the processing, funny once again - I've done this but in a cheeky way. Pretty much I just sent a message from server -> Client, something like "startTransmission" or whatever. the client then keeps filling its memorystream full of data recieved until it gets the "endTransmission" command. From then, we simply just use the Image.FromStream() method to read the image stored in the memoryStream object, and set that to the background image....

    Me.BackgroundImage = Image.FromStream(theMemStream)

    so whilst you are recieving the data in bytes() array on the client, you keep writing it into a memorystream until you recieve that command, and you keep checking on every data you recieved for that command.

    alternatively I guess you could just try to keep reading and appending to the memorystream until no more data left to be read (but remember TCP/IP works in a funny yet incredible way where if you send data, its not recieved in the way you sent it. That's normal).

    Different ways of going about doing things



  • Chryso

    OK i made a memorystream, and checked if an image was about to be sent like this:

    Dim bytes(client.ReceiveBufferSize) As Byte

    client.GetStream.Read(bytes, 0, CInt(client.ReceiveBufferSize))

    Dim clientdata As Char() = Encoding.ASCII.GetString(bytes).Trim("").ToCharArray

    If clientdata = "BeginTransmission" Then

    ReceivingImage = True

    This part works fine and sets ReceivingImage to true when an image is going to be sent. Then when data is received:

    ImageBuffer.Write(buffer, 0, buffer.Length)

    But I can't figure out when the image transmission ends. Any ideas



  • lord_8

    funny I've done this! Take a look at this on creating screen shot:

    http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=841156&SiteID=1

    with that you can save it to any file format you like.

    to send it over tcp connection, when saving just give it the network stream/socket stream to send it to instead of the filename



  • Gerrit L

    well basically once you have sent the image from the server/client, just send it a string afterwards to mark the end of transmission like "EndTransmission" I'm sure there is a better way that I can't think right now but generally doing it this way, it is possible

  • send start transmission command

  • reciever prepares to keep reading data until no more data left to be read

  • server sends data

  • client recieves data and checks if current data recieve is a marker of end transmission

  • server finishes sending data and sends end transmission marker

  • client recieves end transmission marker and begins to assemble the image



  • SillyMS

    Excellent idea, thanks for your help.

  • H Reyes

     

    It's difficult to believe I'm seeing this conversation.

    Good programs like net meeting send Deltas, meaning the difference between the current image and the last image. You don't just compress an image and send it. You send the changes in the image.

     

    I suspect this is accomplished by and Anding Bitblt on the client.



  • D.R.B.

    tke175 wrote:
    There are so many programs out there that do this like VNC, NetMeeting, BindView NetRC, pcAnywhere, Remote Desktop Connection. Some of which are freeware or shareware others are inexpensive. I do not see why you would attempt to reinvent the wheel if you are just looking for the end result. If you are looking to learn something new then enjoy the quest. I would agree though that the better versions of the desktop sharing applictions transmit image deltas not the whole screen.

    I'm only attempting this kind of programming to 'see how it works'. I don't expect this program to become popular, and I will not release it comercially. It is simply for my personal use to help broaden my knowledge.



  • GSK_phili

    indeed and its a good way to do so too :-)

  • Rakesh Bhardwaj

    There are so many programs out there that do this like VNC, NetMeeting, BindView NetRC, pcAnywhere, Remote Desktop Connection. Some of which are freeware or shareware others are inexpensive. I do not see why you would attempt to reinvent the wheel if you are just looking for the end result. If you are looking to learn something new then enjoy the quest. I would agree though that the better versions of the desktop sharing applictions transmit image deltas not the whole screen.
  • Rudemusik

    ReneeC,

    I will implement using Deltas in the final version. For now I just wanted to see how to send an image over a TCP connection in the first place.



  • VB Screen Sharing