View Single Post
  #4  
Old 03-20-2012, 12:54 PM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Quote:
Originally Posted by Gunderak View Post
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(0false);
}

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");

__________________
Reply With Quote