INSTALL@lib$+"SOCKLIB" PROC_initsockets host$=FN_gethostname PRINThost$ hostent%=FN_sethost(host$) hostip%=!!hostent%!12 PRINTFNipaddrs(hostip%) ON CLOSE PROC_exitsockets : QUIT : REM important ON ERROR PROC_exitsockets : REPORT : END : REM important PROCfindname dest$=host$ : REM if testing locally REPEAT socnum%=FN_tcpconnect(dest$,"12325") UNTILsocnum%>0 PRINT"Peer name: "FN_getpeername(socnum%) PRINT"Connection established: "socnum% DIMbuffer%255 PRINT "Sending bytes" try%=0 REPEAT ?buffer%=48+try% : REM Printable bytes PRINT try% : WAIT 25 : REM success%=FN_writesocket(socnum%,buffer%,1) try%+=1 UNTILtry%=10 success%=FN_writelinesocket(socnum%,"") : REM newline PRINT "Sending lines" try%=0 REPEAT PRINT try% : WAIT 25 : REM success%=FN_writelinesocket(socnum%,"Hello"+STR$(try%)) try%+=1 UNTILtry%=10 PROC_closesocket(socnum%) : REM close before exit PRINT "Finished" PROC_exitsockets END : DEFFNipaddrs(addr%) =STR$(addr%AND255)+"."+STR$(addr%>>>8AND255)+"."+STR$(addr%>>>16AND255)+"."+STR$(addr%>>>24AND255) : DEFPROCfindname SYS"LoadLibrary","dnsapi.dll"TOdnsapi% SYS"GetProcAddress",dnsapi%,"DnsQuery_A"TO`DnsQuery` SYS"GetProcAddress",dnsapi%,"DnsRecordListFree"TO`DnsRecordListFree` DIMdnsr{pNext%,pName%,wType{l&,h&},wDataLength{l&,h&},dwFlags%,dwTtl%,dwReserved%,dwData%} query$="Computer2" SYS`DnsQuery`,query$,1,1,0,dnsr{},0 rr%=dnsr.pNext% WHILEdnsr.pNext% !(^dnsr{}+4)=dnsr.pNext% PRINT$$dnsr.pName% " ",FNipaddrs(dnsr.dwData%) ENDWHILE dest$=FNipaddrs(dnsr.dwData%) SYS`DnsRecordListFree`,rr%,0 SYS"FreeLibrary",dnsapi% ENDPROC
INSTALL@lib$+"SOCKLIB" PROC_initsockets host$=FN_gethostname PRINThost$ hostent%=FN_sethost(host$) hostip%=!!hostent%!12 PRINTFNipaddrs(hostip%) ON CLOSE PROC_exitsockets : QUIT : REM important ON ERROR PROC_exitsockets : REPORT : END : REM important PROCfindname PRINT"Checking connection" REPEAT socnum%=FN_tcplisten(host$,"12325") IF socnum%<0 THEN PRINT FN_socketerror UNTILsocnum%>0 PRINT"Listening" REPEAT success%=FN_check_connection(socnum%) WAIT 0 UNTILsuccess%>0 PRINT "Connected to "FN_getpeername(success%) REM buffer content need to be parsed DIMbuffer%255 REPEAT inbyte%=FN_readsocket(success%,buffer%,255) IF inbyte%>0 THEN PRINT "Received ";inbyte%;" bytes" FOR I%=0 TO inbyte%-1 PRINT CHR$buffer%?I%; NEXT ELSE WAIT 0 ENDIF UNTIL inbyte%=-1 PRINT "Disconnected" PROC_exitsockets END : DEFFNipaddrs(addr%) =STR$(addr%AND255)+"."+STR$(addr%>>>8AND255)+"."+STR$(addr%>>>16AND255)+"."+STR$(addr%>>>24AND255) : DEFPROCfindname SYS"LoadLibrary","dnsapi.dll"TOdnsapi% SYS"GetProcAddress",dnsapi%,"DnsQuery_A"TO`DnsQuery` SYS"GetProcAddress",dnsapi%,"DnsRecordListFree"TO`DnsRecordListFree` DIMdnsr{pNext%,pName%,wType{l&,h&},wDataLength{l&,h&},dwFlags%,dwTtl%,dwReserved%,dwData%} query$="Computer1" SYS`DnsQuery`,query$,1,1,0,dnsr{},0 rr%=dnsr.pNext% WHILEdnsr.pNext% !(^dnsr{}+4)=dnsr.pNext% PRINT$$dnsr.pName% " ",FNipaddrs(dnsr.dwData%) ENDWHILE dest$=FNipaddrs(dnsr.dwData%) SYS`DnsRecordListFree`,rr%,0 SYS"FreeLibrary",dnsapi% ENDPROC