Author Topic: TCPObjects, how do they work?  (Read 2053 times)

Right, I have gotten a succesful connection but I am trying to send something to the server. It sends but it does not operate like I need it to. Look here for example, it keeps saying this;



Are you trying to create a TCP server?



It surprised me too!

http://joncraton.org/blog/46/netcat-for-windows

Even though it's pretty much identical I don't like how it works compared to NIX.
aw, not default :(


HEY WORDY, DON'T MAKE THE MISTAKE I DID.



SEE THAT CONNECTIONTCP THING?

YOU HAVE TO DO THIS:

ConnectionTCP::onLine(%this, %line)

YOU CANNOT DO THIS:

TCPServer::onLine(%this, %line)

stuff WILL START EXPLODING AND PORT WILL KILL YOU.

my brain exploded with confusion when i saw that code, i got it working though

You need to define ConnectionTCP::Functionshereloel

YOU CAN'T loving DEFINE CLIENT FUNCTIONS ON THE SERVER.



PORT, HOLD YOUR FINGERS AND DON'T POST "DURR"

i know i know;) problem is when i send stuff nothing happens

TRACE()??????
POST LOG???

I need more info than that

i trace, it connects fine with the server IP and port, when i .send("#101") it doesn't react to it, no need for console log

perhaps it is waiting for the end of the line

try sending \r\n\r\n at the end and see if that changes anything
Figuring that out was crucial when I had this problem: http://forum.blockland.us/index.php?topic=188089.0

not \r\n\r\n

just \r\n

gave me a error-



apart from that, still nothing


if(!isObject(WBClient))
   new ScriptObject(WBClient);

function WBClient::Connect(%this)
{
   %server = "69.64.43.11";
   %port = "29000";
   
   if(!isObject(WBConnector))
      new TCPObject(WBConnector);
   WBConnector.connect(%Server @ ":" @ %port);
   MessageBoxOk("","Sent connection request to the server.");
}

function WBConnector::OnConnected(%this)
{
   MessageBoxOk("","Connection has been successful.");
}

function WBConnector::OnConnectFailed(%this)
{
   MessageBoxOK("","Connection to the server failed.");
}

function WBConnector::OnDisconnect(%This)
{
   MessageBoxOK("","Connection to the server has been terminated.");
   WBConnector.delete();
}


and for the server sided bit




   if(!isObject(WBServer))
      new ScriptGroup(WBServer);

   if(!isObject(WBListener))
      new TCPObject(WBListener).listen(29000);
      
   function WBListener::onConnectRequest(%this,%ip,%socket)
   {
      if(isObject(%this.connection[%ip]))
      {
        echo(%this.getName() @ ": Got duplicate connection from" SPC %ip);
        %this.connection[%ip].disconnect();
        %this.connection[%ip].delete();
      }
       echo(%this.getName() @ ": Creating connection to" SPC %ip);
       %this.connection[%ip] = new TCPobject("",%socket) { class = ConnectionTCP; parent = %this; };
   WBServer.add(%this.connection[%ip]);
   }
   function ConnectionTCP::onLine(%this,%line)
   {
      switch$(getWord(%line, 0))
            {
               case "#101":
                  echo("#Test data recieved.");
                  announce("#test data recieved.");
                  return;
               
               default:
                  echo(%line);
            }
   }


i try do .send("#101"); and it just gives that error that i posted before

You guys might want to look at Truce's Torque Webserver. http://forum.blockland.us/index.php?topic=142682.0