(firewall anmachen, um zu sehen, dass da was ankommt)
Code: Alles auswählen
Procedure OpenNetworkConnectionUDP(ServerName$, Port.l)
!Conn equ Esp+8
!Wsa equ Esp+24
!Sock equ Esp+424
WsaData.WSADATA
Connection.SOCKADDR_IN
Sock.l
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
!if ~ defined _gethostbyname@4 | defined @f
!extrn _gethostbyname@4
!@@:
!end if
;
!if ~ defined _WSAStartup@8 | defined @f
!extrn _WSAStartup@8
!@@:
!end if
;
!if ~ defined _socket@12 | defined @f
!extrn _socket@12
!@@:
!end if
;
!if ~ defined _htons@4 | defined @f
!extrn _htons@4
!@@:
!end if
;
!if ~ defined _connect@12 | defined @f
!extrn _connect@12
!@@:
!end if
;
!if ~ defined _WSACleanup@0 | defined @f
!extrn _WSACleanup@0
!@@:
!end if
;;;;;;;;;;;;;;;;;;
!MOV Eax, [Esp]
!OR Eax, Eax
!JZ @f
!PUSH Eax
!CALL _gethostbyname@4
!OR Eax, Eax
!JZ @f
!MOVSX Ebx, word [Eax+8]
!CMP Ebx, 2
!JNE @f
!MOV Ecx, [Eax+12]
!MOV Ecx, [Ecx]
!MOV Ecx, [Ecx]
!MOV [Conn+4], Ecx
!LEA Eax, [Wsa]
!PUSH Eax
!PUSH $0002
!CALL _WSAStartup@8
!OR Eax, Eax
!JNZ @f
!CMP byte [Wsa], 2
!JL @f
!PUSH 0
!PUSH 2
!PUSH 2
!CALL _socket@12
!CMP Eax, -1
!JE @f
!MOV [Sock], Eax
!MOV word [Conn], 2
!PUSH dword [Esp+4]
!CALL _htons@4
!MOV word [Conn+2], ax
!MOV Eax, dword [Sock]
!PUSH dword 16
!LEA Eax, [Conn+4]
!PUSH Eax
!PUSH dword [Sock+8]
!CALL _connect@12
!CALL _WSACleanup@0
!MOV Eax, [Sock]
ProcedureReturn
!@@:
!CMP byte [Wsa], 0
!JE @f
!CALL _WSACleanup@0
!@@:
;;;;;;;;;;;;;
!Restore Conn
!Restore Wsa
!Restore Sock
EndProcedure
InitNetwork()
ServerID = OpenNetworkConnectionUDP("localhost", 777)
If ServerID
Debug SendNetworkString(ServerID, "test")
Debug SendNetworkData(ServerID, AllocateMemory(7), 7)
CloseNetworkConnection(ServerID)
EndIf