Quote:
Originally Posted by Gunderak
Thanks for the informative post, I will post in the code gallery when it is complete 
I will still be using PHP to handle a few things on the webservers side.
Edit: Already ran into a problem...
|
You need to bind to a port, not connect to a server. See Grattpd or my FTP server for examples.
Here's the listen socket code I'm using:
PHP Code:
function onCreated() {
this.bind(0, false);
}
function onBind() {
// this line can be used if you have a PHP script setup for
// automatically redirecting requests to the current port;
// see the example script in the forum post
// requestURL("http://graalcenter.org/update.php?pass=replace_me&port=" @ this.port);
// this is probably only useful if you're not using a PHP
// script for redirection; could be a bit of a pain since
// it's always changing.
echo("HTTP: Bound to " @ this.optionDB.ip @ ":" @ this.port @ ", waiting for connections...");
}
function onNewClient(clientSocket) {
clientSocket.optionDB = this.optionDB;
clientSocket.join("http_clientsocket");
}
and the socket's creation:
PHP Code:
function onCreated() {
// get server IP
temp.req = requestURL("http://www.whatismyip.com/automation/n09230945.asp");
waitfor(req, "onReceiveData", 30);
this.ip = req.data[0];
// destroy if existing
if (isObject("HTTPListenSocket")) {
HTTPListenSocket.destroy();
}
// create the socket
this.listenSocket = new TSocket("HTTPListenSocket");
this.listenSocket.optionDB = this;
this.listenSocket.join("http_listensocket");
}