classes/class_tcpserver #204
Replies: 3 comments 1 reply
-
|
Just had a good conversation with ChatGPT on a sample setup: Not sure what's up with TCPServer's receipt of String data from a client's i.e. if client here is a StreamPeerTCP connected with a status of 2 to a TCPServer, I could see the data over the wire with Wireshark, but TCPServer always saw the raw data as [0, 0]: But when I changed to using a Variant from the client and in the server it worked: I don't think there's a bug, but I could not sus out anything wrong with the initial attempt at using Strings, but Variant is probably better long-term anyways since you can then JSON/YAML it up. It was just weird because String or Variant, over the wire I saw valid packets getting [PSH, ACK] from the server: 0000 02 00 00 00 45 00 00 40 49 1c 40 00 80 06 00 00 ¯_(ツ)_/¯ |
Beta Was this translation helpful? Give feedback.
-
|
I have done a few TCP servers on Java & other languages, but for the love of me I fail to understand Godot's version of TCP server & sockets Would it be possible to get an example of how they work? The UDPServer class had both a server & a client example so that we could understand After some researches, I really realised that there are literally no posts thoroughly explaining what to do, which objects represent what, and I am not the only one to feel that way, as far as I'm concerned |
Beta Was this translation helpful? Give feedback.
-
|
Simple TCP server example: Replace contents in use_stream() with your desired behavior. extends Node;
const DEFAULT_PORT: int = 19388;
var server: TCPServer;
func use_stream(stream: StreamPeerTCP):
# Your Code Here
pass;
func _ready():
server = TCPServer.new();
server.listen(DEFAULT_PORT);
func _process(_dt: float):
while server.is_connection_available():
var stream: StreamPeerTCP = server.take_connection();
use_stream(stream); |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
classes/class_tcpserver
Inherits: RefCounted< Object A TCP server. Description: A TCP server. Listens to connections on a port and returns a StreamPeerTCP when it gets an incoming connection. Note: When exporting to Andro...
https://docs.godotengine.org/en/stable/classes/class_tcpserver.html
Beta Was this translation helpful? Give feedback.
All reactions