PBXB64 Netzwerk

TCP & UDP Standard

Vollständiges TCP- und UDP-Netzwerk with TCP OPEN/CLOSE/SEND/RECV/LISTEN/ACCEPT and UDP OPEN/CLOSE/SEND/RECV. Server, Clients bauen, and Peer-to-Peer-Anwendungen. Echte Win32-Socket-API (WSAStartup, socket, bind, listen, accept, send, recv).

TCP-Client & Server

TCP client example
FUNCTION PBMAIN() AS LONG LOCAL hSocket AS LONG LOCAL buffer AS STRING LOCAL sent AS LONG ' Connect to server TCP OPEN "192.168.1.1" AS #1 PORT 8080 ' Send data TCP SEND #1, "Hello Server", sent ' Receive response TCP RECV #1, 1024, buffer PRINT "Server said: "; buffer TCP CLOSE #1 FUNCTION = 0 END FUNCTION

TCP OPEN creates a client connection. TCP SEND sends data with a sent-bytes count. TCP RECV receives up to a specified buffer size. TCP CLOSE releases the socket. TCP LISTEN/ACCEPT for server-side.

UDP - Verbindungslos

UDP send/receive
FUNCTION PBMAIN() AS LONG LOCAL buffer AS STRING LOCAL received AS LONG ' Open UDP socket UDP OPEN "0.0.0.0" AS #1 PORT 5000 ' Send to peer UDP SEND #1, "192.168.1.2", 5001, "Hello UDP!" ' Receive from any peer UDP RECV #1, 1024, received, buffer PRINT "Got: "; buffer UDP CLOSE #1 FUNCTION = 0 END FUNCTION

UDP ist verbindungslos - jeder Sendevorgang spezifiziert das Ziel address and port. UDP RECV returns the sender info and byte count. Ideal für Discovery, Streaming, and lightweight protocols.

HOST ADDR / HOST NAME

DNS resolution
FUNCTION PBMAIN() AS LONG LOCAL ip AS STRING LOCAL name AS STRING ip = HOST ADDR("smart-ai-robot.com") PRINT "IP: "; ip name = HOST NAME("192.168.1.1") PRINT "Name: "; name FUNCTION = 0 END FUNCTION

HOST ADDR resolves a hostname to IP address. HOST NAME performs reverse DNS lookup. Both use real gethostbyname/getaddrinfo Win32 APIs.

Zurück zur Feature-Liste