' TCP Server via Winsock DECLARE — socket, bind, listen, accept
#COMPILE EXE
#DIM ALL

DECLARE FUNCTION WSAStartup LIB "WS2_32.DLL" (BYVAL wVersionRequired AS LONG, BYREF lpWSAData AS LongPtr) AS LONG
DECLARE FUNCTION WSACleanup LIB "WS2_32.DLL" () AS LONG
DECLARE FUNCTION socket LIB "WS2_32.DLL" (BYVAL af AS LONG, BYVAL type AS LONG, BYVAL protocol AS LONG) AS LONG
DECLARE FUNCTION bind LIB "WS2_32.DLL" (BYVAL s AS LONG, BYREF name AS LongPtr, BYVAL namelen AS LONG) AS LONG
DECLARE FUNCTION listen LIB "WS2_32.DLL" (BYVAL s AS LONG, BYVAL backlog AS LONG) AS LONG
DECLARE FUNCTION accept LIB "WS2_32.DLL" (BYVAL s AS LONG, BYREF addr AS LongPtr, BYREF addrlen AS LONG) AS LONG
DECLARE FUNCTION closesocket LIB "WS2_32.DLL" (BYVAL s AS LONG) AS LONG

FUNCTION PBMAIN() AS LONG
    PRINT "TCP Server via Winsock DECLARE:"
    PRINT "1. WSAStartup"
    PRINT "2. socket(AF_INET, SOCK_STREAM, 0) -> s"
    PRINT "3. bind(s, addr, sizeof(addr))"
    PRINT "4. listen(s, 5)"
    PRINT "5. accept(s, NULL, NULL) -> client"
    PRINT "6. recv/send on client socket"
    PRINT "7. closesocket + WSACleanup"
    FUNCTION = 0
END FUNCTION
