OpenStream(http::..) and port

BlitzMax Forums/BlitzMax Beginners Area/OpenStream(http::..) and port

Polan(Posted 2014) [#1]
Local url$ = "http::localhost:1234"
Local stream:TStream = OpenStream(url)

How can I tell which port shall be used? This doesn't work.


FBEpyon(Posted 2014) [#2]
127.0.0.1 Is what I would suggest you use when trying to access your local host.

Port can be defined by you, and is used mostly for port forwards and such to the service, but if you are using your localhost, you shouldn't need a port.

Regards,

FBEpyon


xlsior(Posted 2014) [#3]
but if you are using your localhost, you shouldn't need a port.


... Does not compute.

Most webservers will run on port 80 so not specifying a port number will default HTTP traffic to a remote port 80 -- but that has absolutely nothing to do with whether or not it's localhost or a remote server that you're talking to.

ANY program that speaks TCP/IP listens on a port - if you wanted to, you can run three hundred webservers on your own computer all bound to your localhost IP, just listening on different ports.

The port number is how you specify with which paticular instance you want to communicate.


Brucey(Posted 2014) [#4]
Looking at the source code for httpstream :
Local stream:TStream=TSocketStream.CreateClient( server,80 )

one imagines that you will be using port 80 for some time.

You could either,
1) change the module to suite your needs with a hard coded port number
2) create an equivalent of your own type that accepts a port number too
3) use a 3rd party module (like BaH.libcurl, for example) that is designed to do more than just open standard web pages.

I'd go for 2 or 3.


Polan(Posted 2014) [#5]
Thank you for suggestions, I've solved it by opening TCP socket and sending custom GET request.