rott/kf_sources/NetworkTest/Classes/TestTcp.uc
2026-07-14 20:27:09 +07:00

117 lines
2.9 KiB
Ucode

class TestTcp extends TcpLink;
var bool cooldown;
var array<byte> tttt;
var TestObj g1, g2, g3, g4;
public function Initialize()
{
linkMode = MODE_Binary;
receiveMode = RMODE_Manual;
SetTimer(5.0, true);
Log("[TestTcp] Binding port...");
if (BindPort(1234) > 0) {
Log("Success!");
}
else
{
Log("Failed! So much for the `TcpLink` :(");
return;
}
Log("[TestTcp] Putting socket in listen mode...");
if (Listen()) {
Log("Success!");
}
else {
Log("Failed right at th finish line! So much for the `TcpLink` :(");
}
}
/*
event Timer()
{
if (linkState == STATE_Initialized) {
Log("[TestTcp] STATUS:" @ "Sockets is initialized");
}
else if (linkState == STATE_Ready) {
Log("[TestTcp] STATUS:" @ "Port bound, ready for activity");
}
else if (linkState == STATE_Listening) {
Log("[TestTcp] STATUS:" @ "Listening for connections");
}
else if (linkState == STATE_Connecting) {
Log("[TestTcp] STATUS:" @ "Attempting to connect");
}
else if (linkState == STATE_Connected) {
Log("[TestTcp] STATUS:" @ "Open and connected");
}
else if (linkState == STATE_ListenClosePending) {
Log("[TestTcp] STATUS:" @ "Socket in process of closing");
}
else if (linkState == STATE_ConnectClosePending) {
Log("[TestTcp] STATUS:" @ "Socket in process of closing");
}
else if (linkState == STATE_ListenClosing) {
Log("[TestTcp] STATUS:" @ "Socket in process of closing");
}
else if (linkState == STATE_ConnectClosing) {
Log("[TestTcp] STATUS:" @ "Socket in process of closing #2");
}
}
*/
event Tick(float delta)
{
local TestObj o1, o2, o3, o4;
local int i, dataRead, totalRead, iter;
local byte data[255];
local string message;
if (cooldown)
{
cooldown = false;
return;
}
if (!IsDataPending()) {
return;
}
dataRead = ReadBinary(255, data);
while (dataRead > 0)
{
iter += 1;
totalRead += dataRead;
//Log("{" $ dataRead $ "}");
for (i = 0; i < dataRead; i += 1) {
//message $= Chr(data[i]);
tttt[tttt.length] = data[i];
}
if (iter > 100) break;
if (dataRead == 255)
{
dataRead = ReadBinary(255, data);
//Log("!{" $ dataRead $ "}!");
}
else {
cooldown = true;
break;
}
}
StopWatch(false);
for (i = 0; i < 10000; i += 1) {
g1 = new(none, string(i)) class'TestObj';
}
StopWatch(true);
Log("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
Log("Test run:" @ g1.value);
}
event Accepted()
{
Log("[TestTcp] Accepted!");
}
event Closed()
{
Log("[TestTcp] Closed!");
}
defaultproperties
{
}