Send/receive files.

BlitzMax Forums/BlitzMax Beginners Area/Send/receive files.

tonyg(Posted 2006) [#1]
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..
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...

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?


FlameDuck(Posted 2006) [#2]
You might want to not use port 8080. If someone is running another program (like Apache Tomcat) on that port, you will not be able to bind the socket.

Other than that it looks good, but I'm kinda drunk and tired, so you may want to get a second opinion.