Blockland Forums > Modification Help
Server TCP Objects not functioning properly, client are fine - Solved
Lugnut:
Simply put, whenever I attempt to make a server with a TCP object it fails.
Client ones, which connect to servers are fine.
One can plainly see the stuffload of echoes I have everywhere, but they rarely give me any useful information.
--- Code: ---new TCPObject(lugsTCPServ);
function lugsTCPServ::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("Client", %socket) { class = lugsTCPServ; parent = %this;};
}
function lugsTCPServ::onConnected(%this)
{
echo("SRVR:Connected");
}
function lugsTCPServ::onConnectFailed(%this)
{
echo("SRVR:Connection Failed");
}
function lugsTCPServ::onDisconnect(%this)
{
echo("SRVR:Disconnected");
}
function lugsTCPServ::onLine(%this, %line)
{
echo(%this);
echo(%line);
%mode = getword(%line, 0);
echo(%mode);
%msg = strReplace(%line, getword(%line, 0), "");
echo(%msg);
switch$(%mode)
{
case "CHAT:":
echo("SRVR:CHAT:" SPC %msg);
case "WARNMSG":
warn("SRVR:WARN:" SPC %msg);
default:
echo("SRVR:Message received, unknown mode:" SPC %line);
}
return;
}
lugsTCPServ.listen(8675);
--- End code ---
solved: i needed to get onLine from "client" in the code.
see the part where there's "lugTCPServ::onLine"?
That needs to be Client::onLine, using the ambiguous (therefore poorly chosen) names above.
Port:
Exactly how isn't it working?
Also, I recommend representing elements in packets using a single byte instead of a long string.
In a initialization function, you could define the protocol, i.e.:
%this.callback[ "\x01" ] = "kill_everyone";
%this.callback[ "\x02" ] = "delete";
Then, when receiving a packet, do a variable lookup on the first character.
Lugnut:
probably should've mentioned that
:c
as you can see by my lovely echoes, on my end it does this (i'm using putty in raw mode to connect to localhost:8675)
Blockland:
--- Code: ---==>exec("base/tcpserver.cs");
Executing base/tcpserver.cs.
Binding server port to default IP
lugsTCPServ: Creating connection to IP:127.0.0.1:26054
Add-Ons/System_ReturnToBlockland/support/networking.cs (222): Unknown command onLine.
Add-Ons/System_ReturnToBlockland/support/networking.cs (222): Unknown command onLine.Add-Ons/System_ReturnToBlockland/support/networking.cs (319): Unknown command onDisconnect. //After closing PuTTY
--- End code ---
PuTTY:
--- Code: ---asdf
asdf
--- End code ---
As you can see, it doesn't even echo the line, or %this, as specified in lugsTCPServer::onLine
Port:
well the problem is fairly obvious
what do you want the server to receive lines from?
* the server
* the client
--- Quote ---%this.connection[%ip] = new TCPobject("Client", %socket) { class = lugsTCPServ; parent = %this;};
--- End quote ---
--- Quote ---function lugsTCPServ::onLine(%this, %line)
--- End quote ---
before you go saying "there's the class thing"; class inheritance is broken for TCPObjects
function Client::onLine(%this, %line)
also name the client type more privately
don't give it such an ambiguous name that other mods might use
Lugnut:
i don't understand, I need to do
Client::onLine?