ReCT Documentation

v2.2.3

Net Package


Include this Package with


package net;

[i] This package includes ReCTs TCP Networking functions.


ConnectTCPClient(ip -> string, port -> int)

Tries to Connect to the IP with the given port. When successful, will return a Tcp Client.


ListenOnTCPPort(port -> int)

Will start to listen for Tcp Clients on the given port. When successful, will return a Tcp Listener.


OpenSocket(socket -> TCPSocket)

Will wait for a Client to connect and return a Tcp Socket.


The legacy TCP Datatypes have been deprecated and removed in ReCT v2.2. They are now replaced with new Classes. The old functions still work and will now return the new Classes.



TCP Client

A TCP Client can be created by either using its Constructor or the ConnectTCPClient() function.

var client <- make TCPClient("ip address", <port>);

To read out messages you can either use ReadLine() to read a whole line of text from the InputStream or Read() which will only read and return the next Character from the InputStream.

var line <- client -> ReadLine();
var nextChar <- client -> Read();

To write and send messages you can use the Write() and WriteLine() functions. The only difference between them is that WriteLine() will put a newline after the message.
IMPORTANT: Write() and WriteLine() only write to the SendBuffer but dont actually send the data for that you need to call the Flush() function. If you just want to write a line and send it instantly you can use WriteFlush()

client -> Write("this message will be sent");
client -> WriteLine("together with the one above");
client -> Flush();

client -> WriteFlush("this will be sent on its own, instantly");


TCP Listener

A TCP Listener can be created by either using its Constructor or the ListenOnTCPPort() function.

var listener <- make TCPListener(<port>);

The Listener is just there to open Sockets for clients when they connect. To open a socket and wait for a Client just call OpenSocket(). (The static OpenSocket() will also work)

var socket <- listener -> OpenSocket();

TCP Socket

A TCP Socket can be created by either using the Listeners OpenSocket() function or the static OpenSocket() function.

var socket <- listener -> OpenSocket();

To read out messages you can either use ReadLine() to read a whole line of text from the InputStream or Read() which will only read and return the next Character from the InputStream.

var line <- socket -> ReadLine();
var nextChar <- socket -> Read();

To write and send messages you can use the Write() and WriteLine() functions. The only difference between them is that WriteLine() will put a newline after the message.
IMPORTANT: Write() and WriteLine() only write to the SendBuffer but dont actually send the data for that you need to call the Flush() function. If you just want to write a line and send it instantly you can use WriteFlush()

socket -> Write("this message will be sent");
socket -> WriteLine("together with the one above");
socket -> Flush();

socket -> WriteFlush("this will be sent on its own, instantly");