| Blockland Forums > Modification Help |
| TCPObject::get(%this) Resource |
| (1/2) > >> |
| Brian Smithers:
I was bored so I made a simple TCPObject.get(); function Usage TCPObject.host = "blockland.us:80"; //place:port TCPObject.file = "/index.html"; //file TCPObject.get(); // Must be connected Code function TCPObject::get(%this) { //Example of TCPObject.file: /index.html //Example of TCPObject.host: blockland.us:80 %this.send("GET " @ %this.file @ " HTTP/1.1\r\n"); %this.send("Host: " @ %this.host @ "\r\n"); %this.send("Content-Location: " @ %this.file @ "\r\n\r\n"); } Example Function function TCPObject::get(%this) { %this.send("GET " @ %this.file @ " HTTP/1.1\r\n"); %this.send("Host: " @ %this.host @ "\r\n"); %this.send("Content-Location: " @ %this.file @ "\r\n\r\n"); } function TempTCP::onLine(%this,%line) { if(%this.debug) echo(%line); } function TempTCP::autoConnect(%this) { if(strPos(%this.host,"/") > 1) { %this.file = getSubStr(%this.host,strPos(%this.host,"/"),strLen(%this.host)); %this.host = getSubStr(%this.host,0,strPos(%this.host,"/")); %this.connect(%this.host @ ":80"); } else { %this.file = "/"; %this.connect(%this.host @ ":80"); } } function TempTCP::onDisconnected(%this) { %this.delete(); } function TempTCP::onConnected(%this) { %this.debug = 1; %this.get(); } function readPage(%webURL) { new TCPObject(TempTCP) { host = %webURL; }; TempTCP.autoConnect(); } If you want to add anything to it feel free. Also feel free to point out any errors I made. |
| FFSO:
Is the port of the site always the same in this usage or is it different for some websites? |
| Brian Smithers:
--- Quote from: FFSO on March 09, 2012, 04:33:55 PM ---Is the port of the site always the same in this usage or is it different for some websites? --- End quote --- HTTP is always port 80 Though sometimes people use other things. |
| Port:
I don't quite see the point in an entire resource and thread just for this. Writing HTTP requests is already so laughably easy. |
| Kalphiter:
HTTPObject. |
| Navigation |
| Message Index |
| Next page |