tcp sending files/messages

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • joedeene
    Contributor
    • Jul 2008
    • 579

    tcp sending files/messages

    hey there, i want to know how to send files via tcp connection, i am using a socket to connect to the tcplistener. i used to be able to send messages, i remember it was something to do with text.encoding, thats not real big, i can find that on a tutorial again, but i would really appreciate if someone showed me how to send a file. now im not connected asyncronylously . i just use the simple .connect method for now. so idk if i wanna use the beginsend, and then beginreceive, because when i just use socket.sendfile that could work, but how would i receive it on the server's side. would i have to read the network stream, and put it together? plz help... i do have some code, im willing to show if anyone suggests im just getting people to do my "homework". ok, plz help, thanks in advance =)
  • secutos
    New Member
    • Aug 2008
    • 15

    #2
    First, know that this will most likely (99%) not answer your question, but will instead give you a headstart. If you were transferring a big file, you would probably have to send bits at a time. First, you convert that "big file" into a byte array. You cut off a bit of the byte array to send. For that bit you just cut off, tag it so the other side knows that there is more to come (there is a lot more byte arrays to send). To tag it, add a few bytes with a special code like "UNFINISHED ". When the other side reads the byte array and sees "UNFINISHED ", it stores it into a bigger byte array storage and waits for more.

    Correct me if i'm wrong.

    Comment

    • Plater
      Recognized Expert Expert
      • Apr 2007
      • 7872

      #3
      1) Connect socket
      2) Open file
      3) Send file bytes on socket
      4) Repeat step 3 until all bytes are sent
      5) Close file
      6) Close socket (or whatever you feel like for your protocol)

      Comment

      • joedeene
        Contributor
        • Jul 2008
        • 579

        #4
        Originally posted by Plater
        1) Connect socket
        2) Open file
        3) Send file bytes on socket
        4) Repeat step 3 until all bytes are sent
        5) Close file
        6) Close socket (or whatever you feel like for your protocol)

        how would i come across doing this ? like for step 3 use the socket.sendfile ? and how to read it? like i'd rather do a network stream from just the tcpclient.getst ream and write to that.

        Comment

        • Plater
          Recognized Expert Expert
          • Apr 2007
          • 7872

          #5
          How you do it is up to you.
          You just send bytes accross a socket. So open your file up, read in the bytes and send the bytes over the socket.
          How you control the talking back and forth is all up to you.

          Comment

          • joedeene
            Contributor
            • Jul 2008
            • 579

            #6
            Originally posted by Plater
            How you do it is up to you.
            You just send bytes accross a socket. So open your file up, read in the bytes and send the bytes over the socket.
            How you control the talking back and forth is all up to you.

            i know that but i tried sending a simple small jpeg over the networkstream and i'd get most of it, but it would should like a gray(blank) spot where i guess it didnt receive all of the data, idk i guess i'll work on it, and i dont remember that code either, i'll just google some more

            Comment

            Working...