Class StreamPeerTcp
- Namespace
- Godot
- Assembly
- GodotSharp.dll
A stream peer that handles TCP connections. This object can be used to connect to TCP servers, or also is returned by a TCP server.
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("StreamPeerTCP")]
public class StreamPeerTcp : StreamPeer, IDisposable
- Inheritance
-
StreamPeerTcp
- Implements
- Inherited Members
Constructors
StreamPeerTcp()
public StreamPeerTcp()
Methods
Bind(int, string)
Opens the TCP socket, and binds it to the specified local address.
This method is generally not needed, and only used to force the subsequent call to ConnectToHost(string, int) to use the specified host
and port
as source address. This can be desired in some NAT punchthrough techniques, or when forcing the source network interface.
public Error Bind(int port, string host = "*")
Parameters
Returns
ConnectToHost(string, int)
Connects to the specified host:port
pair. A hostname will be resolved if valid. Returns Ok on success.
public Error ConnectToHost(string host, int port)
Parameters
Returns
DisconnectFromHost()
Disconnects from host.
public void DisconnectFromHost()
GetConnectedHost()
Returns the IP of this peer.
public string GetConnectedHost()
Returns
GetConnectedPort()
Returns the port of this peer.
public int GetConnectedPort()
Returns
GetLocalPort()
Returns the local port to which this peer is bound.
public int GetLocalPort()
Returns
GetStatus()
Returns the status of the connection, see StreamPeerTcp.Status.
public StreamPeerTcp.Status GetStatus()
Returns
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_nameName of the method to check for.
Returns
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_nameName of the signal to check for.
Returns
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_nameName of the method to invoke.
args
NativeVariantPtrArgsArguments to use with the invoked method.
ret
godot_variantValue returned by the invoked method.
Returns
Poll()
Poll the socket, updating its state. See GetStatus().
public Error Poll()
Returns
SetNoDelay(bool)
If enabled
is true
, packets will be sent immediately. If enabled
is false
(the default), packet transfers will be delayed and combined using Nagle's algorithm.
Note: It's recommended to leave this disabled for applications that send large packets or need to transfer a lot of data, as enabling this can decrease the total available bandwidth.
public void SetNoDelay(bool enabled)
Parameters
enabled
bool