1 procedure connect_np_server(); 2 var 3 addr: sockaddr_in; 4 ver: WORD; 5 dt: WSADATA; 6 begin 7 MAKEWORD(1, 1); 8 WSAStartup(ver, dt); 9 addr.sin_family := PF_INET; 10 addr.sin_addr.S_addr := inet_addr(Pchar(HSIP)); 11 addr.sin_port := htons(7010); 12 sNp_server := socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); 13 connect(sNp_server, addr, sizeof(addr)); 14 end; 15 16 17 function OnNpKey(Addr : Pchar; nLen : Integer; OutAddr : Pchar) : Integer; Stdcall; 18 var 19 Len : Word; 20 NP : TNP; 21 begin 22 Result := 0; 23 24 ZeroMemory(@NP, SizeOf(NP)); 25 NP.Count := 1; 26 27 Len := nLen; 28 Len := ntohs(Len); 29 NP.KKbuf[0] := $01; 30 NP.KKbuf[1] := $10; 31 CopyMemory(@NP.KKBuf[2], @Len, 2); 32 CopyMemory(@NP.KKbuf[4], @Addr[0], nLen); 33 34 connect_np_server(); 35 Send(sNp_server, NP, SizeOf(NP), 0); 36 ZeroMemory(@NP, SizeOf(NP)); 37 Recv(sNp_server, NP, SizeOf(NP), 0); 38 CloseSocket(sNp_server); 39 40 CopyMemory(@Len, @NP.KKBuf[0], 2); 41 Len := ntohs(Len); 42 43 CopyMemory(@OutAddr[0], @NP.KKBuf[2], Len); 44 CopyMemory(@OutAddr[$190], @Len, 2); 45 end;
第一天来 记录自己的学习笔记
时间: 2024-10-09 20:14:57