TCPSocket

BlitzMax Forums/BlitzMax Programming/TCPSocket

How can i get a data stream from a socket?

s:tSocket = createTCPSocket()
ip=hostip("www.ansa.it")
if connectsocket(s, ip, 80) print "connected"
closeSocket(s)


in this way i should be connnected to ansa.it (correct me if not). And now? if i want to get the page and simply put the html to console, how can i?

(sorry if there's english mistakes)

don't use it if you have no experience with sockets and don't need to go that low level.

you can simply use http::ansa.it and the stream commands for example

O_O

Wow! i didn't know bmax was so "high level"...

I searched for TCPSocket because i was used to Java where there's methods to get streams directly from a socket.

i'm happy to have bought BMax :P

Yes, BM has some nice higher level wrapping.
you can even load images from http:: for example. (incbin:: is a different stream type for incbined data)

you can even load images from http:: for example. (incbin:: is a different stream type for incbined data)


With one small caveat: The loadimage command needs the stream to be seekable (images aren't loaded entirely linearly) so you'd need to cache it locally first, like this:

Local pic:TImage=LoadImage(LoadBank("http::www.blitzbasic.com/img/brllogo-thin.png"))


This will download the image from the web into a seekable memory bank, and loadimage will pull pull it from there.