Results 1 to 30 of 30

Thread: Winsock Picture Transfer

  1. #1

    Thread Starter
    Hyperactive Member MikeBAM's Avatar
    Join Date
    Sep 2000
    Location
    Metro Detroit
    Posts
    284

    Question

    I'm trying to find a way to fransfer a picture from a picture box, image box, or file with winsock. I've tryed transfering a file, and i don't like it. Is there a way out there that you can send pictures like you send text with winsock? If so, do you know where i might be able to find some kind of sample/example program? I know AOL Instant Messager can send pictures in a text box, how can I do it?
    ~* )v( ! /< E *~

  2. #2
    Guest
    Here is an example of how to transfer files with the winsock control.

    Here is another example, but using a status bar.

  3. #3

    Thread Starter
    Hyperactive Member MikeBAM's Avatar
    Join Date
    Sep 2000
    Location
    Metro Detroit
    Posts
    284
    That File transfer example has a lot of bugs in it. I didn't really need a file transfer example anyway. I need a picture transfer with winsock. Is it possible? maybe pictureBox to PictureBox download??
    ~* )v( ! /< E *~

  4. #4
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    It is file transfer .. almost

    A Picture in a picture box is just a series of bytes which of course you can send via winsock. A file is also just a series of bytes and if you know how to do this then it would appear to be straight forward right?

    Well not quite. If you took the file transfer method and made your picturebox first save it's image to a file, then transfer the file to the other end, then read it into the recieving picturebox, you would have a working solution that provides you everything you aksed for.

    If you want to do it without files, then you need to get into the guts of what a DIB is. All bitmaps when read into a pictureBox end up being stored as a Device Independent Bitmap in memory. SO you need to know how to access this DIB data from code and send/recieve it.

    I've done all that with help from the excellent type libraries on http://vbaccelerator.com/ I haven't used winsock though but I believe it would be straight forward enough for someone who knows all the ins and outs of winsock.

    One point you might like to remember though: Consider a 156k bitmap (bmp) that you save as a jpg. The jpg ends up at say 20k. You know you have lost some image quality but because of the huge reduction in size, you can live with it. Sound familiar? Well once it's in memory as a DIB, guess what? It's back up to 156k again. So if you end up going ahead and using winsock to send the data, you'll either have to live with the fact that you are sending almost 8 times the number of bytes that you really need to send, or come up with your own compression mechanism (perhaps these algorithms are publically known?).

    In my opinion, saving to a file (jpeg) then sending the file or at least the bytes in the file, is a far better proposition.

    I'll have a go at doing this myself, only I'm no winsock wiz so it could take me a while

    Cheers
    Paul Lewis

  5. #5
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    put an open statement in like:

    Dim strBuf as string

    Open "C:\FileToSend.bmp" For Input as #1
    Do Until EOF(1)
    Line Input #1, strBuf
    Winsock1.senddata strBuf
    loop
    close #1

    The idea is it loads the file and sends a line at a time through winsock, u then have to reassemble it at the other end by opening a new file and then writing to it each line of data sent and then to save the file with the same name and extension as the original.

    This should work.

  6. #6
    New Member
    Join Date
    Sep 2000
    Posts
    15

    Unhappy Where's the help when you need it??

    I've been working on this problem for months now and with NO avail. When I set out to do this project I thought the transferring of the pictures in the pictureboxs would be the easy part. Boy was I wrong! I know its possible but yet I cant figure it out. Anyway, Mike if you hear of anything let me know. I will email you if I do.

    Wish us luck,
    Todd

  7. #7
    Lively Member
    Join Date
    Aug 2000
    Posts
    114
    When sending the picture using the winsock control send it binary not TEXT(ASCII). Also you need to declare a variable as a byte array not a string. Your code would look something like this.

    Dim bySend() as Byte
    Dim Buffer as Integer
    Dim FileSize as Long
    Dim NumberOfBytesSentSoFar as Long
    Dim iFile as Integer

    iFile = FreeFile
    Open FileToSend For Binary As #iFile

    FileSize = LOF(iFile)

    NumberOfBytesSentSoFar = 0
    Do Until NumberOfBytesSentSoFar >= FileSize
    'Set buffer to the # bytes you want to send
    Buffer = 4096
    If Buffer > FileSize - NumberOfBytesSentSoFar Then
    Buffer = FileSize - NumberOfBytesSentSoFar
    End If

    'Input Binary
    bySend() = InputB(Buffer, iFile)
    Winsock.SendData bySend()
    NumberOfBytesSentSoFar = NumberOfBytesSentSoFar + buffer
    Loop

    Close iFile

  8. #8
    New Member
    Join Date
    Sep 2000
    Posts
    15

    Talking ????

    That all good and Thanks for the help but how do you get that back into another picture box or saved as a file?

    DJTN

  9. #9
    Guest
    Before you start the code that thedee23 suggested, you should send a short string with information about the picture, such as filesize and filename. By receiving the data that thedee23's code sends, you can check if the picture has been fully transferred by comparing the size of the received data and the filesize mentioned in the header (the short string).

    As for the filename, you should be writing the incoming data into the file as it comes in and checking the size of the file everytime to see if it has finished. When it has finished, you can load that picture file into the picture box.

    Sunny

  10. #10
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    Before sending the data you would have to let the client know its receiving a file and the filename, then as the client recieves the text it adds it line by line to a textbox using vbcrlf to goto the next line. once achieved the serevr sends to the client that its the end of the file. The client then assembles the file onto their drive and voila. in the next day or two i will have a demo out for use, (maybe tonight).

  11. #11
    Junior Member
    Join Date
    Sep 2000
    Posts
    25

    Talking I've got just what you need!

    The code comes from chapter 21 of "Visual Basic Programmer's Library", By Christopher J. Bockman, Lars Klander, and Lingyan Tang (published by JAMSA Press - ISBN 1*88413357-6).

    It gives a chat example that share images real-time. The code is too big for posting here, though. Send me your email address, and I'll send it on over....

  12. #12
    New Member
    Join Date
    Sep 2000
    Posts
    15

    Thumbs up winsock

    You can email me @ [email protected]
    or use the link below..... AND THANX!

  13. #13
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

  14. #14
    Guest
    [email protected] <= those are Ls btw...thanks

    Sunny

  15. #15
    Junior Member
    Join Date
    Sep 2000
    Posts
    25

    Thumbs up Done....

    I sent it.... Let me know how it works out.

  16. #16
    New Member
    Join Date
    Sep 2000
    Posts
    15

    Angry File

    The file is missing somthing. activex component cant create object....Set SocketsDLL = New clsSocketsDLL.
    I tried changing the dill to winsock but winsock is unable to do.. SocketsDLL.SendPic(App.Path & "\foo.bmp")
    Where can I find this "socketsdll"?

    Todd

  17. #17
    Junior Member
    Join Date
    Sep 2000
    Posts
    25

    Post It's included.....

    Take another look at the project. It has two .VBP files - two projects. One is prjSocketsDLL.vbp and the othe is prjInternetChat.vbp. You need to compile the DLL also. Doing so will register it on your system.
    Jim Hubbard
    • VB
    • ASP
    • MS SQL Server

    Hubbard Software Corporation
    [email protected]

  18. #18
    New Member
    Join Date
    Sep 2000
    Posts
    15

    Cool I finally got it !

    Thanks to everyone who help me. I really do appreciate it! I finally just used my script for file transfer and made the additional forms transparent during the process and then linked my picture box to the file that was sent. It took a lot of patience but I think it's a lot more stable. Now the fun part begins....The cosmetics! (LOL) 8')

    Thanx again guys, Now I can sleep.
    Todd

  19. #19

    Thread Starter
    Hyperactive Member MikeBAM's Avatar
    Join Date
    Sep 2000
    Location
    Metro Detroit
    Posts
    284
    Whoa! hey! I'm the one who started the post! Can someone PLEASE send it to me? I really need this! Mail me at: [email protected]
    Thanks
    ~* )v( ! /< E *~

  20. #20
    New Member
    Join Date
    Sep 2000
    Posts
    15

    Angry Disappointed

    Well I thought I had it all worked out BUT come to find out the way that I'm sending my pic can only be used on TCP so if someone is on AOL and the other on cable modem they cant send each other their pictures. I'm going to have to send it as a datagram like PSY said:

    Open "C:\FileToSend.bmp" For Input as #1
    Do Until EOF(1)
    Line Input #1, strBuf
    Winsock1.senddata strBuf
    loop
    close #1

    The only bad thing about this is that I dont know how to get all this back into the other picture box on the other users machine in one piece. The pictures have streaks and big black lines in them. Am I ever gonna find the answer??
    If someone knows how to get the datagram into the other picture box in one piece without overflowing the buffer please let me know.

    Todd


  21. #21
    Junior Member
    Join Date
    Sep 2000
    Posts
    25

    Question I don't get it....

    Do you mean that AOL doesn't use TCP/IP? Would that be the service, or the browser?

    I thought everyone using the internet through dial-ups was using TCP/IP now.
    Jim Hubbard
    • VB
    • ASP
    • MS SQL Server

    Hubbard Software Corporation
    [email protected]

  22. #22
    Guest
    DJTN perhaps you could post your code that receives the data, there is likely to be a problem there.

    Sunny

  23. #23
    New Member
    Join Date
    Sep 2000
    Posts
    15

    Drama

    when I send the file to myself it works but when I send it to my friend on AOL I get a wrong protocol error. I connect with a cable modem.


    Todd

  24. #24
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341

    Arrow Ok

    here, i think, is what you have to do, i have not looked at that file that you all have but you need to connect two computers using winsock, as u would normally, then the server lets the client know that its sending a file and the client to get ready, the server has to open the file as binary, then send it on to the client as normal text, the image is then re-assembled, because, the client knows its getting a file the server is sending the data from that file line by line, the client program cretaes and opens the file and inputs the data line by line as it comes, im working on a demo now, it should work like a normal chat program would between two computers and should work with all that AOL crap. I will post a reply when my demos done.

  25. #25
    Hyperactive Member
    Join Date
    Jun 2000
    Location
    Auckland, NZ
    Posts
    411

    AOL question

    I do not know much about AOL except what the acronym stands
    for. Where I connect from there is no AOL (some may find
    that a blessing from what I hear). Anyhow, I assume that
    the AOL system is pretty much a closed one in which the
    only connections allowed in or out are tied up in their
    custom software or front end or something.

    I would assumed therefor, that your friend must find out
    what sockets he has available that will allow a client to
    connect. It is quite possible that AOL do not allow this
    at all.

    As I said, I know nothing about AOL so this is all
    conjecture. Many corporates lock down their internet
    access with firewalls and the like so it's quite possible
    you are faced with a problem like this.

    I'll keep an eye on the thread to see what the final
    outcome with AOL is.

    Cheers
    Paul Lewis

  26. #26
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    I suggest he could get someone like me to port scan him when hes online and then to see what ones are available, Od one of his trusted friends to do it.

  27. #27
    New Member
    Join Date
    Sep 2000
    Posts
    15

    Angry Back @ one

    I'm still having TRAUMA with this script. After I compile the program I can send myself my picture but when I try to send it to my friend on aol I get a runtime error 40006 ' wrong protocol or connection state for the requested transaction or request '. I've tried changing the ports I use and that doesnt help. What am I doing wrong?

    Todd

  28. #28
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    The server is not accepting the connection request, make sure u have a line like this

    winsock1.accept requestid

  29. #29
    Guest
    PaulLewis:
    To transfer a picture in a picturebox does not require any knowledge of the structure of DIB.

    All there is to do is to get the size of the Picture structure (Len(MyPicture)), and use the CopyMemory API to get all the bytes the picture conatins into a byte array, then transfer the data from the byte array to the other side. At the other side we use CopyMemory again to move the byte array into a Picture structure.

    A little example might be (it's scratch):
    Code:
    'We have a PictureBox named PIC.
    Dim bytPicture() As Byte
    Dim lngSize As Long
    
    lngSize = Len(PictureBox.Picture)
    ReDim bytPicture(lngSize - 1) As Byte
    
    CopyMemory bytPicture(0), PIC.Picture, lngSize
    'Here, the bytPicture byte array contains all the
    'info that is needed to construct the picture on
    'the other side.
    It may not be the accurate code, but it's the general idea.

    [Edited by Sc0rp on 10-08-2000 at 05:27 PM]

  30. #30
    Guest

    Talking Just a little addition...

    It may be better to use an StdPicture object or an IPictureDisp object instead of a PictureBox.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width