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 =)
tcp sending files/messages
Collapse
X
-
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. -
Originally posted by Plater1) 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
-
Originally posted by PlaterHow 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 moreComment
Comment