Somebody at CW asked the quickest way to send a file.
I know nothing about networking and was struggling to understand sockets etc so thought I'd give it a go.
This is what I came up with (quick and dirty).
Send..
receive...
Before 'tarting' it up a bit any suggestions? Have I understood the socket commands? Anything to make it faster?
Thanks
P.S. I couldn't use the TStream writebytes method for TSocketStreams. For some reason (probably ignorance) I couldn't use the TSockstream write method either.
Would they make a difference other than a few ms?
I know nothing about networking and was struggling to understand sockets etc so thought I'd give it a go.
This is what I came up with (quick and dirty).
Send..
mysocket:TSocket = CreateTCPSocket() mysocketstream=CreateSocketStream(mysocket) ConnectSocket(mysocket,HostIp("localhost"),8080) mystream:TStream=ReadStream("max1.bmp") CopyStream(mystream,mysocketstream) CloseStream mystream CloseStream mysocketstream CloseSocket mysocket Print "done"
receive...
mysocket:TSocket=CreateTCPSocket() BindSocket(mysocket,8080) SocketListen(mysocket) Repeat myreadsocket:TSocket=SocketAccept(mysocket) If myreadsocket myreadsocketstream=CreateSocketStream(myreadsocket) mystream:TStream=WriteStream("test_out.bmp") CopyStream(myreadsocketstream,mystream) read=True EndIf Until read=True CloseStream(mystream) CloseStream(myreadsocketstream) CloseSocket(myreadsocket) CloseSocket(mysocket) Print "Done"
Before 'tarting' it up a bit any suggestions? Have I understood the socket commands? Anything to make it faster?
Thanks
P.S. I couldn't use the TStream writebytes method for TSocketStreams. For some reason (probably ignorance) I couldn't use the TSockstream write method either.
Would they make a difference other than a few ms?