Table of Contents

Class TcpServer

Namespace
Godot
Assembly
GodotSharp.dll

A TCP server. Listens to connections on a port and returns a StreamPeerTcp when it gets an incoming connection.

Note: When exporting to Android, make sure to enable the INTERNET permission in the Android export preset before exporting the project or using one-click deploy. Otherwise, network communication of any kind will be blocked by Android.

[GodotClassName("TCPServer")]
public class TcpServer : RefCounted, IDisposable
Inheritance
TcpServer
Implements
Inherited Members

Constructors

TcpServer()

public TcpServer()

Methods

GetLocalPort()

Returns the local port this server is listening to.

public int GetLocalPort()

Returns

int

HasGodotClassMethod(in godot_string_name)

Check if the type contains a method with the given name. This method is used by Godot to check if a method exists before invoking it. Do not call or override this method.

protected override bool HasGodotClassMethod(in godot_string_name method)

Parameters

method godot_string_name

Name of the method to check for.

Returns

bool

HasGodotClassSignal(in godot_string_name)

Check if the type contains a signal with the given name. This method is used by Godot to check if a signal exists before raising it. Do not call or override this method.

protected override bool HasGodotClassSignal(in godot_string_name signal)

Parameters

signal godot_string_name

Name of the signal to check for.

Returns

bool

InvokeGodotClassMethod(in godot_string_name, NativeVariantPtrArgs, out godot_variant)

Invokes the method with the given name, using the given arguments. This method is used by Godot to invoke methods from the engine side. Do not call or override this method.

protected override bool InvokeGodotClassMethod(in godot_string_name method, NativeVariantPtrArgs args, out godot_variant ret)

Parameters

method godot_string_name

Name of the method to invoke.

args NativeVariantPtrArgs

Arguments to use with the invoked method.

ret godot_variant

Value returned by the invoked method.

Returns

bool

IsConnectionAvailable()

Returns true if a connection is available for taking.

public bool IsConnectionAvailable()

Returns

bool

IsListening()

Returns true if the server is currently listening for connections.

public bool IsListening()

Returns

bool

Listen(ushort, string)

Listen on the port binding to bindAddress.

If bindAddress is set as "*" (default), the server will listen on all available addresses (both IPv4 and IPv6).

If bindAddress is set as "0.0.0.0" (for IPv4) or "::" (for IPv6), the server will listen on all available addresses matching that IP type.

If bindAddress is set to any valid address (e.g. "192.168.1.101", "::1", etc), the server will only listen on the interface with that addresses (or fail if no interface with the given address exists).

public Error Listen(ushort port, string bindAddress = "*")

Parameters

port ushort
bindAddress string

Returns

Error

Stop()

Stops listening.

public void Stop()

TakeConnection()

If a connection is available, returns a StreamPeerTCP with the connection.

public StreamPeerTcp TakeConnection()

Returns

StreamPeerTcp