// September 2015 // Levee Patroller / Dijk Patrouille // This source file is (c) by Deltares. This source file is open source but only available to select users. Do not redistribute without written permission of Stichting Deltares, Delft, The Netherlands. // This header has been automatically generated. Class MyTcp extends TcpLink; var int RemotePort; var string ServerAddress; var string LF; //sendbuffer var array SendBuffer; //bool connected var bool connected; //------------------------------------------------------------------------------ // First function called (init of the TCP connection) Function InitTcpLinkEventLogger() { LF = Chr(10); // Line feed char "\n" Log("InitTcpLinkEventLogger: Will start TCP connection!"); Resolve(ServerAddress); // Resolve the address of the server } //------------------------------------------------------------------------------ Function int SendText (coerce string Str) // Send the string "Str" + "line feed" car { local int result; if(connected) { result = super.SendText(Str$LF); // Call the super (send the text) } else { SendBuffer.Insert(SendBuffer.length, 1); SendBuffer[SendBuffer.length-1] = str; result = -1; } return result; } //--EVENTS-- // Called when the IP is resolved Event Resolved( IpAddr Addr ) { Log("OK, Address resolved"); Addr.Port = remotePort; BindPort(); // In UnrealTournament, the CLIENT have to make a bind to create a socket! (Not as a classic TCP connection!!!) ReceiveMode = RMODE_Event; // Incomming messages are triggering events LinkMode = MODE_Text; // We expect to receive texts (if we receive datas) Open(Addr); // Open the connection } //------------------------------------------------------------------------------ // If the IP was not resolved... Event ResolveFailed() { log("### Error, resolve failed!!!"); } //------------------------------------------------------------------------------ event Opened() { local int i; log("Ok, connection opened"); connected = true; for(i = 0; i < SendBuffer.length; i++) { SendText(SendBuffer[i]); } } Event Closed() { log("Connection closed"); } Event ReceivedText (string Text) { Log("Read string: "$Text$" Size : "$Len(Text)); } defaultproperties { connected = false; ServerAddress="145.3.11.91" remotePort=3850 }