Author Topic: Got bad connected recieve event[SOLVED]  (Read 630 times)

So I was trying to make a TCP socket server and connecting to it with another blockland client

I keep getting "Got bad connected recieve event" error every time I try to send data

Server:
Code: [Select]
$RPS::Port = 800;

function RPS::onLine(%this,%line)
{
echo(%line);
}

function toggleReciever(%bool)
{
   if(%bool)
   {
      if(!isObject(RPS))
      {
         new TCPObject(RPS);
         RPS.listen($RPS::Port);
      }
      else
      {
         error("Already on");
      }
   }
   else
   {
      if(isObject(RPS))
      {
         RPS.delete();
      }
      else
      {
         error("Nothing to turn off");
      }
   }
}


Client:
Code: [Select]
$BPS::Port = 800;
function BPS::onConnected(%this)
{
   %this.isConnected = true;
   if(%this.sendOnConnect !$= "")
      %this.send(%this.sendonconnect @ "\r\n");
}
function BPS::onDisconnect(%this)
{
   %this.isConnected = false;
}

function BPS::onConnectFailed(%this)
{
   %this.isConnected = false;
}

function BPS::onLine(%this,%line)
{
eval(%line);
}

function sayText(%str)
{
   if(!isObject(BPS))
   {
      new TCPObject(BPS);
      BPS.sendOnConnect = %str;
      BPS.connect("localhost:" @ $BPS::Port);
   }
   else
   {
      if(!BPS.isConnected)
      {
         BPS.sendOnConnect = %str;
         BPS.connect("localhost:" @ $BPS::Port);
      }
      else
      {
         BPS.send(%str @ "\r\n");
      }
   }
}

« Last Edit: July 27, 2013, 02:53:16 PM by Aide33 »

Check the functions defined in this mod

There's one that goes by 'onConnectRequest' or something, and it needs to be defined or something

I'll look through and get a more definitive answer for you now

http://dl.dropbox.com/u/58130173/Releases/Script_TelChat.zip

Got it
Code: [Select]
function RPS::onConnectRequest(%this, %ip, %socket) //Handle connections to the chat server
{
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("ClientTCPObject", %socket)
{
IP = %ip;
};
}
That's presumably all you need, that function would support one client, another client connecting would overwrite the first and then all the data being sent to the first would be sent to the second.

To send data to the client, do ClientTCPObject.send(%data @ "/r/n");
This should be fully functional and compatible with your code.

Use arrays for more than one client. I do that in the linked add on.
« Last Edit: July 27, 2013, 02:52:15 PM by Lugnut »

Check the functions defined in this mod

There's one that goes by 'onConnectRequest' or something, and it needs to be defined or something

I'll look through and get a more definitive answer for you now

http://dl.dropbox.com/u/58130173/Releases/Script_TelChat.zip

Got it
Code: [Select]
function RPS::onConnectRequest(%this, %ip, %socket) //Handle connections to the chat server
{
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("ClientTCPObject", %socket)
{
IP = %ip;
};
}
That's presumably all you need, that function would support one client, another client connecting would overwrite the first and then all the data being sent to the first would be sent to the second.

To send data to the client, do ClientTCPObject.send(%data @ "/r/n");
This should be fully functional and compatible with your code.

Use arrays for more than one client. I do that in the linked add on.
Thanks I checked out the code and it worked