|
Post by zxrportugal on Feb 2, 2021 6:37:17 GMT -5
Hi based in some programs posted on internet , mission : control Plc or relays cards from other devices (smartphone or pcs ) This program in server mode ( not complete ) works very well on Lan (receiving) but using Wan not so good ( using UDP TCP SERVER app for Android ) . In Wan some messages doesn´t pass to graphicbox and it looks that i having problems with buffers/timing ..... working it on LBB Any help ? '*** Simple Server/Client Demo '*** Richard Russell, May 2013 '*** Phil, April 2006 '*** Original program by Brent Thorn, Feb. 2004 'This is a simple "chat" type application. 'You can set up a server, then connect, and 'both sides can talk back and forth.
WindowWidth = 185 WindowHeight = 230 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
groupbox #main.groupbox2, "Mode", 5, 7, 165, 45 TextboxColor$ = "white" textbox #main.textbox1, 5, 77, 155, 25 radiobutton #main.radiobutton3, "Client", [radiobutton3Set], [radiobuttonReset], 100, 22, 58, 25 radiobutton #main.radiobutton4, "Server", [radiobutton4Set], [radiobuttonReset], 15, 22, 65, 25 statictext #main.statictext5, "IP Address", 10, 57, 144, 20 button #main.button7,"Start",[button7Click], UL, 55, 167, 50, 25 statictext #main.scname1, "Display name:", 5, 107, 100, 20 textbox #main.scrname2, 5, 127, 155, 25
open "Chat" for window_nf as #main print #main, "font ms_sans_serif 10" print #main, "trapclose [quit.main]" print #main.radiobutton3, "set" wait
[radiobutton3Set] server=0 print #main.textbox1, "!enable" print #main.textbox1, "!show" print #main.statictext5, "!enable" wait
[radiobutton4Set] server=1 print #main.textbox1, "" print #main.textbox1, "!hide" print #main.statictext5, "!disable" wait
[radiobuttonReset] wait
[quit.main] close #main end
[button7Click] print #main.textbox1, "!contents? var$" if server=0 and validip$(var$)="" then notice "Invalid IP Address":wait print #main.scrname2, "!contents? name$" if name$="" then notice "Please enter a display name":wait close #main addr$=validip$(var$) for x=1 to 4 part$=word$(addr$,x) part$=dechex$(val(part$)) if len(part$)=1 then part$="0"+part$ connaddr$=connaddr$+part$ next x connaddr=hexdec(connaddr$)
global accepts global Recv$ global s$
PORT = 8888 tempo = 10
Open "wsock32" For DLL As #wsock32 Open "WMLiberty" For DLL As #wmlib
' Create a window. WindowWidth = 400 WindowHeight = 400 UpperLeftX=int((DisplayWidth-WindowWidth)/2) UpperLeftY=int((DisplayHeight-WindowHeight)/2)
TexteditorColor$ = "white" texteditor #s.te, 10, 2, 370, 275 TextboxColor$ = "white" textbox #s.t, 10, 287, 370, 25 button #s.s,"Send",[send], UL, 10, 317, 165, 25 button #s.c,"Clear",[clear], UL, 215, 317, 165, 25
open "Chat" for window_nf as #s print #s, "font ms_sans_serif 10" print #s.te, "!font system 10" print #s.te, "!autoresize" print #s.t, "!setfocus" print #s, "trapclose [s_Close]"
' Now create a socket, bind it to a local port, set some ' network events to trap, and start listening for clients.
Call WinsockInit
Err = 1 ' Assume failure If WSAStartup(MAKEWORD(2, 2)) = 0 Then #s.te "> Winsock initialized."
sockaddr.sinfamily.struct = 2 'AF_INET sockaddr.sinzero.struct = String$(8, 0) sockaddr.sinport.struct = htons(PORT) If sockaddr.sinport.struct <> -1 Then if server = 1 then sockaddr.sinaddr.struct = GetLocalIP() else sockaddr.sinaddr.struct = htonl(connaddr) end if If sockaddr.sinaddr.struct <> -1 Then sock = socket(2, 1, 0) 'AF_INET=2:SOCK_STREAM=1 If sock <> -1 Then #s.te "> Socket created."
Callback lpfnCB, SockProc( Long, Long, Long, Long ), Long rc = SetWMHandler(HWnd(#s), _WM_USER, lpfnCB, 1) 'FD_READ=1:FD_WRITE=2:FD_OOB=4:FD_ACCEPT=8:FD_CONNECT=16:FD_CLOSE=32 flags=1 or 8 or 32 if server=0 then flags=flags or 16 If WSAAsyncSelect(sock, HWnd(#s), _WM_USER, flags) <> -1 Then #s.te "> Events selected."
if server=1 then if bind(sock) = 0 and listen(sock, 1) = 0 Then #s.te "> Listening for incoming connections." Err=0 end if else if connect(sock)=-1 and WSAGetLastError()=10035 then #s.te "> Connect requested." Err=0 end if end if End If End If End If End If End If
If Err Then #s.te "> ERROR: "; GetWSAErrorString$(WSAGetLastError()) If sock <> -1 Then rc = closesocket(sock) End If Else if server=1 then myip = GetLocalIP() #s.te "> Clients connect to ["; InetNtoA$(myip); "]" end if End If
[start] [s_Wait] Scan p=p+1 if p<2 then gosub [consola] gosub [estadosaídas] CallDLL #kernel32, "Sleep", _ 1 As Long, _ rc As Void GoTo [s_Wait] [s_Close] Call WSACleanup
Close #s
Close #wmlib Close #wsock32
End
[send] print #s.t, "!contents? var$" if server=1 then if Send(accepts,name$+"> "+var$+chr$(13),0)=-1 then #s.te "> ERROR: "; GetWSAErrorString$(WSAGetLastError()) else if Send(sock,name$+"> "+var$+chr$(13),0)=-1 then #s.te "> ERROR: "; GetWSAErrorString$(WSAGetLastError()) end if #s.te name$+"> "+var$ print #s.t, "" goto [s_Wait]
[clear] print #s.t, "" print #s.t, "!setfocus" goto [s_Wait]
'*** Application Procedures ***
Function SockProc( hWnd, uMsg, sock, lParam ) ' Callback function to handle a Windows message ' forwarded by WMLiberty. Called when a relevant ' network event occurs.
Select Case LOWORD(lParam) Case 1 'FD_READ buf$ = Recv$(sock, 8192, 0) do i = instr(buf$, chr$(13)) if i then #s.te woBang$(left$(buf$,i-1)) buf$ = mid$(buf$,i+1) end if loop until (i = 0) #s.te woBang$(buf$); Case 8 'FD_ACCEPT accepts = accept(sock) #s.te ">Socket: ";accepts
#s.te "> Accepted connection from "; _ InetNtoA$(sockaddr.sinaddr.struct); ":"; _ htons(sockaddr.sinport.struct); "." case 16 'FD_CONNECT if HIWORD(lParam)=0 then #s.te "> Connect complete." x=Send(sock,"Hi!"+chr$(13),0) gosub [estadosaídas] else #s.te "> Connect failed." end if Case 32 'FD_CLOSE #s.te "> Connection Closed." gosub [estadosaídas] End Select SockProc=1 End Function
Sub WinsockInit ' Initializes structs used in Winsock calls. Struct hostent, _ hname As Long, _ haliases As Long, _ haddrtype As Word, _ hlength As Word, _ haddrlist As Long
Struct sockaddr, _ sinfamily As Short, _ sinport As UShort, _ sinaddr As ULong, _ sinzero As Char[8]
Struct WSAData, _ wVersion As Word, _ wHighVersion As Word, _ szDescription As Char[257], _ szSystemStatus As Char[129], _ iMaxSockets As Word, _ iMaxUdpDg As Word, _ lpVendorInfo As Long End Sub
Function woBang$( raw$ ) ' Kludge to print a string that could start with an ' exclamation point, or bang (!). Am I missing something? woBang$ = raw$ bangs = 0 While Mid$(raw$, bangs+1, 1) = "!" bangs = bangs + 1 Wend If bangs Then bang$ = Left$(raw$, bangs) woBang$ = Mid$(raw$, bangs+1)
#s.te "!Lines ln" #s.te "!Line "; ln; " ln$" #s.te "!Select "; Len(ln$)+1; " "; ln #s.te "!Insert bang$" #s.te "!Select 1 1" End If End Function
'*** General Procedures ***
Function LOWORD( dw ) LOWORD = (dw And 65535) End Function
Function HIWORD( dw ) HIWORD = int((dw / 65536)) End Function
Function MAKEWORD( b1, b2 ) MAKEWORD = b1 Or (256 * b2) End Function
Function String$( num, ch ) If num > 0 Then String$ = Chr$(ch) While Len(String$) < num String$ = String$ + String$ Wend String$ = Left$(String$, num) End If End Function
'*** Winsock Wrappers ***
Function GetHostByAddr$( addr ) Struct p, addr As ULong p.addr.struct = addr CallDLL #wsock32, "gethostbyaddr", _ p As Struct, _ 4 As Long, _ 2 As Long, _ 'AF_INET=2 phe As Long If phe Then helen = Len(hostent.struct) CallDLL #kernel32, "RtlMoveMemory", _ hostent As Struct, _ phe As ULong, _ helen As Long, _ rc As Void GetHostByAddr$ = WinString(hostent.hname.struct) End If End Function
Function GetHostByName$( sName$ ) CallDLL #wsock32, "gethostbyname", _ sName$ As Ptr, _ phe As ULong If phe Then helen = Len(hostent.struct) CallDLL #kernel32, "RtlMoveMemory", _ hostent As Struct, _ phe As ULong, _ helen As Long, _ rc As Void GetHostByName$ = WinString(hostent.hname.struct) End If End Function
Function GetHostName$() buf$ = Space$(256)+Chr$(0) CallDLL #wsock32, "gethostname", _ buf$ As Ptr, _ 256 As Long, _ rc As Long GetHostName$ = Trim$(buf$) End Function
Function GetLocalIP() sName$ = GetHostName$() CallDLL #wsock32, "gethostbyname", _ sName$ As Ptr, _ phe As ULong If phe Then helen = Len(hostent.struct) CallDLL #kernel32, "RtlMoveMemory", _ hostent As Struct, _ phe As ULong, _ helen As Long, _ rc As Void plong = hostent.haddrlist.struct Struct p, addrlist As ULong CallDLL #kernel32, "RtlMoveMemory", _ p As Struct, _ plong As ULong, _ 4 As Long, _ rc As Void plong = p.addrlist.struct Struct p, addr As ULong hlength = hostent.hlength.struct CallDLL #kernel32, "RtlMoveMemory", _ p As Struct, _ plong As ULong, _ hlength As Long, _ rc As Void GetLocalIP = p.addr.struct End If End Function
Function GetWSAErrorString$( errnum ) Select Case errnum Case 10004: e$ = "Interrupted system call." Case 10009: e$ = "Bad file number." Case 10013: e$ = "Permission Denied." Case 10014: e$ = "Bad Address." Case 10022: e$ = "Invalid Argument." Case 10024: e$ = "Too many open files." Case 10035: e$ = "Operation would block." Case 10036: e$ = "Operation now in progress." Case 10037: e$ = "Operation already in progress." Case 10038: e$ = "Socket operation on nonsocket." Case 10039: e$ = "Destination address required." Case 10040: e$ = "Message too long." Case 10041: e$ = "Protocol wrong type for socket." Case 10042: e$ = "Protocol not available." Case 10043: e$ = "Protocol not supported." Case 10044: e$ = "Socket type not supported." Case 10045: e$ = "Operation not supported on socket." Case 10046: e$ = "Protocol family not supported." Case 10047: e$ = "Address family not supported by protocol family." Case 10048: e$ = "Address already in use." Case 10049: e$ = "Can't assign requested address." Case 10050: e$ = "Network is down." Case 10051: e$ = "Network is unreachable." Case 10052: e$ = "Network dropped connection." Case 10053: e$ = "Software caused connection abort." Case 10054: e$ = "Connection reset by peer." Case 10055: e$ = "No buffer space available." Case 10056: e$ = "Socket is already connected." Case 10057: e$ = "Socket is not connected." Case 10058: e$ = "Can't send after socket shutdown." Case 10059: e$ = "Too many references: can't splice." Case 10060: e$ = "Connection timed out." Case 10061: e$ = "Connection refused." Case 10062: e$ = "Too many levels of symbolic links." Case 10063: e$ = "File name too long." Case 10064: e$ = "Host is down." Case 10065: e$ = "No route to host." Case 10066: e$ = "Directory not empty." Case 10067: e$ = "Too many processes." Case 10068: e$ = "Too many users." Case 10069: e$ = "Disk quota exceeded." Case 10070: e$ = "Stale NFS file handle." Case 10071: e$ = "Too many levels of remote in path." Case 10091: e$ = "Network subsystem is unusable." Case 10092: e$ = "Winsock DLL cannot support this application." Case 10093: e$ = "Winsock not initialized." Case 10101: e$ = "Disconnect." Case 11001: e$ = "Host not found." Case 11002: e$ = "Nonauthoritative host not found." Case 11003: e$ = "Nonrecoverable error." Case 11004: e$ = "Valid name, no data record of requested type." Case Else: e$ = "Unknown error "; errnum; "." End Select GetWSAErrorString$ = e$ End Function
Function InetNtoA$( inaddr ) CallDLL #wsock32, "inet_ntoa", _ inaddr As ULong, _ pstr As ULong InetNtoA$ = WinString(pstr) End Function
Function Recv$( s, buflen, flags ) Recv$ = Space$(buflen)+Chr$(0) CallDLL #wsock32, "recv", _ s As Long, _ Recv$ As Ptr, _ buflen As Long, _ flags As Long, _ buflen As Long Recv$ = Left$(Recv$, buflen) print Recv$ s$ = Recv$ End Function
Function Send( s, buf$, flags ) buflen=len(buf$) CallDLL #wsock32, "send", _ s As Long, _ buf$ As Ptr, _ buflen As Long, _ flags As Long, _ Send As Long End Function
'*** Winsock Thin Wrappers ***
Function accept( s ) Struct p, length As Long p.length.struct = Len(sockaddr.struct) CallDLL #wsock32, "accept", _ s As Long, _ sockaddr As Struct, _ p As Struct, _ accept As Long End Function
Function bind( s ) namelen = Len(sockaddr.struct) CallDLL #wsock32, "bind", _ s As Long, _ sockaddr As Struct, _ namelen As Long, _ bind As Long End Function
Function closesocket( s ) CallDLL #wsock32, "closesocket", _ s As Long, _ closesocket As Long End Function
Function htonl( hostlong ) CallDLL #wsock32, "htonl", _ hostlong As ULong, _ htonl As ULong End Function
Function htons( hostshort ) CallDLL #wsock32, "htons", _ hostshort As Word, _ htons As Word End Function
Function inetaddr( cp$ ) CallDLL #wsock32, "inet_addr", _ cp$ As Ptr, _ inetaddr As ULong End Function
Function listen( s, backlog ) CallDLL #wsock32, "listen", _ s As Long, _ backlog As Long, _ listen As Long End Function
Function socket( af, type, protocol ) CallDLL #wsock32, "socket", _ af As Long, _ type As Long, _ protocol As Long, _ socket As Long End Function
Function WSAAsyncSelect( s, hWnd, wMsg, lEvent ) CallDLL #wsock32, "WSAAsyncSelect", _ s As Long, _ hWnd As ULong, _ wMsg As ULong, _ lEvent As Long, _ WSAAsyncSelect As Long End Function
Sub WSACleanup CallDLL #wsock32, "WSACleanup", _ r As Void End Sub
Function WSAGetLastError() CallDLL #wsock32, "WSAGetLastError", _ WSAGetLastError As Long End Function
Function WSAStartup( wVersionRequested ) CallDLL #wsock32, "WSAStartup", _ wVersionRequested As Word, _ WSAData As Struct, _ WSAStartup As Long End Function
Function connect( s ) namelen = Len(sockaddr.struct) CallDLL #wsock32, "connect", _ s As Long, _ sockaddr As Struct, _ namelen As Long, _ connect As Long End Function
'*** WMLiberty Thin Wrappers ***
Function SetWMHandler( hWnd, uMsg, lpfnCB, lSuccess ) CallDLL #wmlib, "SetWMHandler", _ hWnd As Long, _ uMsg As Long, _ lpfnCB As Long, _ lSuccess As Long, _ SetWMHandler As Long End Function
function validip$(var$) fail=0 for x=1 to len(var$) if mid$(var$,x,1)="." then var$=left$(var$,x-1)+" "+right$(var$,len(var$)-x) next x if word$(var$,5)<>"" then goto [endoffuncvalidip] if word$(var$,4)="" then goto [endoffuncvalidip] for x=1 to 4 buf$=word$(var$,x) buf$=trim$(buf$) if len(buf$)>3 then fail=1 if val(buf$)=0 and buf$<>"0" then fail=1 next x if fail=0 then validip$=var$ [endoffuncvalidip] end function [consola] BackgroundColor$ = "blue" ForegroundColor$ = "red"
WindowWidth = DisplayWidth /1.25 WindowHeight = DisplayHeight /1.25 UpperLeftX = 0 UpperLeftY = 0 STATICTEXT #main.Label1, "Dados Recebidos", 4, 200, 100, 20
TEXTBOX #main.DataReceived, 4, 240, 150, 20 STATICTEXT #main.Label1, "Mensagem a enviar" , 4, 80, 100, 20 TEXTBOX #main.DataToSend, 4,100, 150, 20
BUTTON #main.send, "Enviar >>", [SendData],ul, 170, 100 ,100, 25 button #main.botao1, "botao1", [Botao1] ,ul, 400, 250 ,100, 75 BUTTON #main.botao2, "botao2", [Botao2] ,ul, 650, 250 ,100, 75 BUTTON #main.botao3, "botao3", [Botao3] ,ul, 900, 250 ,100, 75 BUTTON #main.botao4, "botao4", [Botao4] ,ul, 1150, 250 ,100, 75 BUTTON #main.botao5, "sequenciador 123", [Botao5] ,ul, 400, 550 ,100, 75 BUTTON #main.botao6, "reset sequenciador", [Botao6] ,ul, 525, 550 ,100, 75
STATICTEXT #main.credit, "By SPD ", 20, 160*2+30, 200, 30 graphicbox #main.0, 400, 50, 100, 100 graphicbox #main.1, 650, 50, 100, 100 graphicbox #main.2, 900, 50, 100, 100 graphicbox #main.3, 1150, 50, 100, 100 open "comunicação udp prototipo" for window as #main
print #main, "trapclose [close]" print #main.DataReceived, "Dados a receber aparecem aqui..." print #main.DataToSend, "escreva a mensagem a enviar..." print #main.0, "home" 'center the pen print #main.0, "down" 'ready to draw print #main.0, "fill black" 'fill the graphics area black print #main.1, "home" 'center the pen print #main.1, "down" 'ready to draw print #main.1, "fill black" 'fill the graphics area black print #main.2, "home" 'center the pen print #main.2, "down" 'ready to draw print #main.2, "fill black" 'fill the graphics area black print #main.3, "home" 'center the pen print #main.3, "down" 'ready to draw print #main.3, "fill black" 'fill the graphics area black return [Botao1] s$="s0@" packet$ = "misturadora 1 " gosub [udp] gosub [estadosaídas]
wait
[Botao2] s$="s1@" packet$ = "misturadora 2" gosub [udp] gosub [estadosaídas] wait
[Botao3] s$="s2@" packet$ = "misturadora 3" gosub [udp] gosub [estadosaídas] wait
[Botao4] s$="s3@" packet$ = "misturadora 4" gosub [udp] gosub [estadosaídas] wait
[Botao5]
scan x=x+1
s$="s3s@" packet$ = "sequenciador s3s " gosub [udp] gosub [estadosaídas]
for y=0 to tempo
print y : print x : print time$() next y s$="s3r@" gosub [udp] gosub [estadosaídas]
packet$ = "sequenciador s3r " s$="s0s@" gosub [udp] gosub [estadosaídas] for y=0 to tempo
print y : print x : print time$() next y
s$="s0r@" packet$ = "sequenciador s0r "
gosub [udp] gosub [estadosaídas] s$="s0r@" packet$ = "sequenciador s0r " gosub [udp] gosub [estadosaídas]
s$="s1s@" packet$ = "sequenciador s1s " gosub [udp] gosub [estadosaídas]
for y=0 to tempo
print y : print x : print time$() next y
s$="s1r@" packet$ = "sequenciador " gosub [udp]
gosub [estadosaídas] s$="s2s@" packet$ = "sequenciador " gosub [udp] gosub [estadosaídas]
for y=0 to tempo
print y : print x : print time$() next y
gosub [estadosaídas] s$="s2r@" packet$ = "sequenciador "
gosub [udp] gosub [estadosaídas] if temp<100 then goto [Botao5] else goto [start] wait ' acaba botoes [close] print "saindo" close #main wait [estadosaídas] v=v+1 print "loop estado de saídas numero" , v , time$()
scan
print #main.DataReceived, packet$ if s$= "s0@" then print #main.0, "fill red" if s$= "PLAY" then print #main.0, "fill red" if s$= "s0s@" then print #main.0, "fill red" if s$= "s0r@" then print #main.0, "fill black" if s$= "s0s@" then print #main.0, "fill red" print packet$ if s$= "s1@" then print #main.1, "fill red"
if s$= "s1s@" then print #main.1, "fill red" if s$= "s1r@" then print #main.1, "fill black" if RXdata$= "s1rs@" then print #main.1, "fill red" print packet$ if s$= "s2@" then print #main.2, "fill red" if s$= "s2s@" then print #main.2, "fill red" if s$= "s2r@" then print #main.2, "fill black" if s$= "s2r@" then print #main.2, "fill black" if RXdata$= "s2s@" then print #main.2, "fill red" if s$= "s3@" then print #main.3, "fill red" if s$= "s3s@" then print #main.3, "fill red" if s$= "s3r@" then print #main.3, "fill black"
if s$= "s3s@" then print #main.3, "fill red" if s$= "s3r@" then print #main.3, "fill black"
return wait [udp] return [/div]
|
|
|
Post by Chris Iverson on Feb 3, 2021 15:18:12 GMT -5
Hope you don't mind, I added code tags to your post to make it easier to read and copy.
I'm going over it now, but there are many issues that come in to play with WAN. NAT, port forwarding, hairpinning, many things.
Are you sometimes getting contact, and sometimes not, or are you never getting a connection when going over WAN?
|
|
|
Post by zxrportugal on Feb 3, 2021 17:26:22 GMT -5
Hi thanks for your response, i´m getting many times contact i think it depends of actual speed of mobile net . but sometimes the message comes, its showed on chat window but the information doesn´t pass to the graphic box . when i press to fast the buttons on smarphone after a while the programm craches... in lbb said error at line 0 . in LAN of course its more faster and its more dificult to crash .i think is a buffer and timer problem , but i don´t now how to solve it. i´m reading some codes made in c++ but that language for me it´s chinese...but i now some commands are very similar leading with winsock . Off corse my programing skills are very basic... i´m tryng to learn with programs you had write but i´m stucked right now . Many hours passed no big advances... thanks for your help
|
|
|
Post by Rod on Feb 4, 2021 4:48:46 GMT -5
Can we separate the two problems. Can you simulate a series of messages using an array or a text file. Feed these messages to your program and lets see if it is the parsing and drawing code that is flawed or the tcp ip messaging.
|
|
|
Post by zxrportugal on Feb 5, 2021 6:21:35 GMT -5
Hi another example program ( with bugs... using UDP) working super fast in WAN
big problem here is recv fuction is in blocking mode and i´m stucked here .
Of course for people who doesn´t no ...we have to open port 8888 in router for WAN comunications . download the android app UDP TCP SERVER free configure with WAN IP and port, configure number of buttons if you want , set the message in the buttons , et voila ... for LAN no router configurations are needed . i need help for put recv function in unblock mode and create a time loop to use the bottons on window when we want .... thanks
[inicio] BackgroundColor$ = "blue" ForegroundColor$ = "red"
WindowWidth = DisplayWidth /1.25 WindowHeight = DisplayHeight /1.25 UpperLeftX = 0 UpperLeftY = 0 STATICTEXT #main.Label1, "Dados Recebidos", 4, 200, 100, 20
TEXTBOX #main.DataReceived, 4, 240, 150, 20 STATICTEXT #main.Label1, "Mensagem a enviar" , 4, 80, 100, 20 TEXTBOX #main.DataToSend, 4,100, 150, 20
BUTTON #main.send, "Enviar >>", [SendData],ul, 170, 100 ,200, 25 button #main.botao1, "botao1", [Botao1] ,ul, 400, 250 ,100, 75 BUTTON #main.botao2, "botao2", [Botao2] ,ul, 650, 250 ,100, 75 BUTTON #main.botao3, "botao3", [Botao3] ,ul, 900, 250 ,100, 75 BUTTON #main.botao4, "botao4", [Botao4] ,ul, 1150, 250 ,100, 75 BUTTON #main.botao5, "sequenciador 123", [Botao5] ,ul, 400, 550 ,100, 75 BUTTON #main.botao6, "reset sequenciador", [Botao6] ,ul, 525, 550 ,100, 75
STATICTEXT #main.credit, "By SPD ", 20, 160*2+30, 200, 30 graphicbox #main.0, 400, 50, 100, 100 graphicbox #main.1, 650, 50, 100, 100 graphicbox #main.2, 900, 50, 100, 100 graphicbox #main.3, 1150, 50, 100, 100 open "comunicação udp prototipo" for window as #main
print #main, "trapclose [close]" print #main.DataReceived, "Dados a receber aparecem aqui..." print #main.DataToSend, "escreva a mensagem a enviar..." print #main.0, "home" 'center the pen print #main.0, "down" 'ready to draw print #main.0, "fill black" 'fill the graphics area black print #main.1, "home" 'center the pen print #main.1, "down" 'ready to draw print #main.1, "fill black" 'fill the graphics area black print #main.2, "home" 'center the pen print #main.2, "down" 'ready to draw print #main.2, "fill black" 'fill the graphics area black print #main.3, "home" 'center the pen print #main.3, "down" 'ready to draw print #main.3, "fill black" 'fill the graphics area black 'MAIN PROGRAM LOOP
[start] scan gosub [structInit]
Call OpenWinsock port = 8888 sock = OpenUDPServSocket(port) 'get start time [inicio2] startTime = time$("ms") print "startTime - " , startTime
while info$ <> "END" sckadrSize = len(sockaddr.struct) sckadr$ = space$(sckadrSize) recv = recvfrom(sock, buf$, 1024, 0, sckadr$, sckadrSize) If recv < 0 then print "recv error: ";WSAGetLastError() a = closesocket(sock) a = WSACleanup() call CloseWinsock end end if
info$ = left$(buf$, recv) s$ = info$ GOSUB [estadosaídas] scan print info$ sendBuf$ = "testReturn" ret = sendto(sock, sendBuf$, len(sendBuf$), sckadr$) if ret = -1 then print "Send error - ";WSAGetLastError() end if wend scan
'INSERT FUNCTIONS HERE '================================================ '=========COMMON FUNCTIONS======================= '================================================ Function OpenUDPServSocket(Port) HINTS.aiFlags.struct = 1 'Attempt to get a local address for hosting err = getsrvaddrinfo(str$(Port)) if err <> 0 then Notice "getaddrinfo failed: 0x";dechex$(err);" ";err a = WSACleanup() Call CloseWinsock end End If
'Fill the addrinfo struct with the info returned in the pointer lpAddrinfo = lp.addrinfo.struct size = len(addrinfo.struct) CallDLL #kernel32, "RtlMoveMemory",_ addrinfo as struct,_ lpAddrinfo as ulong,_ size as long,_ ret as void
'Fill the sockaddr struct from the returned addrinfo struct lpSockaddr = addrinfo.aiAddr.struct size = len(sockaddr.struct) CallDLL #kernel32, "RtlMoveMemory",_ sockaddr as struct,_ lpSockaddr as ulong,_ size as long,_ ret as void
CallDLL #kernel32, "RtlMoveMemory",_ sockaddrin as struct,_ sockaddr as struct,_ size as long,_ ret as void
print sockaddrin.sinPort.struct
'Create the socket with the types returned from getaddrinfo sock = socket(addrinfo.aiFamily.struct, addrinfo.aiSocktype.struct, addrinfo.aiProtocol.struct) If sock = hexdec("FFFFFFFF") then err = WSAGetLastError() Notice "Socket creation failed: 0x";dechex$(err);" ";err Call freeaddrinfo a = WSACleanup() call CloseWinsock end End If
'Bind the port If bind(sock, sockaddr.struct, addrinfo.aiAddrlen.struct) <> 0 then err = WSAGetLastError() Notice "Bind failed: 0x";dechex$(err);" ";err call freeaddrinfo a = closesocket(sock) a = WSACleanup() close #ws2 end End If
call freeaddrinfo 'addrinfo no longer needed OpenUDPServSocket = sock End Function
Function DoRecv$(sock, ByRef IPAddr$) buf$ = space$(1024) 'ret = recvfrom(sock, buf$, 1024, 0) If (ret = -1) then err = WSAGetLastError() Notice "recvfrom error: 0x";dechex$(err);" ";err a = closesocket(sock) a = WSACleanup() Call CloseWinsock end End If
DoRecv$ = left$(buf$, ret)
IPAddr$ = winstring(inetntoa(sockaddrin.sinAddr.struct)) End Function
Sub OpenWinsock open "ws2_32" for DLL as #ws2 err = WSAStartup() if err <> 0 then Notice "WSAStartup failed: 0x";dechex$(err);" ";err Call CloseWinsock end end if End Sub
Sub CloseWinsock a = WSACleanup() close #ws2 End Sub
Function recvfrom(sock, byref buf$, bufSize, flags, byref sockaddr$, byref sockaddrSize) buf$ = space$(bufSize) struct a, b as long a.b.struct = sockaddrSize c$ = sockaddr$ CallDLL #ws2, "recvfrom",_ sock as ulong,_ buf$ as ptr,_ bufSize as long,_ flags as long,_ c$ as ptr,_ a as struct,_ recvfrom as long
sockaddr$ = c$ sockaddrSize = a.b.struct End Function
Function recv(sock, byref buf$, bufLen) CallDLL #ws2, "recv",_ sock as ulong,_ buf$ as ptr,_ bufLen as long,_ 0 as long,_ recv as long End Function
Function sendto(sock, buf$, bufLen, sockAddr$) c$ = sockAddr$ size = len(c$)
CallDLL #ws2, "sendto",_ sock as ulong,_ buf$ as ptr,_ bufLen as long,_ 0 as long,_ c$ as ptr,_ size as long,_ sendto as long End Function
Function inetntoa(inAddr) CallDLL #ws2, "inet_ntoa",_ inAddr as ulong,_ inetntoa as ulong End Function
Function send(socket, Buf$, bufLen) CallDLL #ws2, "send",_ socket as ulong,_ Buf$ as ptr,_ bufLen as long,_ 0 as long,_ send as long End Function
Function bind(socket, lpSockAddr$, namelen) temp$ = lpSockAddr$ CallDLL #ws2, "bind",_ socket as ulong,_ temp$ as ptr,_ namelen as long,_ bind as long End Function
Function connect(socket, byref lpSockAddr, namelen) CallDLL #ws2, "connect",_ socket as ulong,_ sockaddr as struct,_ namelen as long,_ connect as long End Function
Function socket(family, socktype, protocol) CallDLL #ws2, "socket",_ family as long,_ socktype as long,_ protocol as long,_ socket as ulong End Function
Function WSAGetLastError() CallDLL #ws2, "WSAGetLastError",_ WSAGetLastError as long End Function
Function closesocket(sock) CallDLL #ws2, "closesocket",_ sock as ulong,_ closesocket as long End Function
Function getsrvaddrinfo(pServiceName$) CallDLL #ws2, "getaddrinfo",_ 0 as ulong,_ pServiceName$ as ptr,_ HINTS as struct,_ lp as struct,_ getsrvaddrinfo as long End Function
Function getaddrinfo(host$, pServiceName$) CallDLL #ws2, "getaddrinfo",_ host$ as ptr,_ pServiceName$ as ptr,_ HINTS as struct,_ lp as struct,_ getaddrinfo as long End Function
Sub freeaddrinfo CallDLL #ws2, "freeaddrinfo",_ lp.addrinfo.struct as ulong,_ ret as void End Sub
Function WSAStartup() word = MAKEWORD(2, 2) CallDLL #ws2, "WSAStartup",_ word as word,_ WSADATA as struct,_ WSAStartup as long End Function
Function WSACleanup() CallDLL #ws2, "WSACleanup",_ WSACleanup as long End Function
Function MAKEWORD(loWord, hiWord) MAKEWORD = (loWord AND hexdec("FF")) + (hiWord * hexdec("100")) End Function
Function LOBYTE(word) LOWORD = word AND hexdec("FF") End Function
Function HIWORD(word) HIWORD = (int(word / hexdec("100")) AND hexdec("FF")) End Function
Sub RtlCopyMemory lpDest, lpSource, uLength print "in sub"
'CallDLL #kernel32, "SetHandleCount",_ ' lpSource as ulong,_ ' lpStruct as ulong
struct lp2, addrinfo as ulong lp2.addrinfo.struct = addrinfo.struct
CallDLL #kernel32, "RtlMoveMemory",_ lp2 as struct,_ lp.addrinfo.struct as ulong,_ uLength as ulong,_ ret as void End Sub
[structInit] struct WSADATA,_ wVersion as word,_ wHighVersion as word,_ wsaDescription as CHAR[258],_ wsaSystemStatus as char[130],_ iMaxSockets as word,_ iMaxUdpDg as word,_ lpVendorInfo as ulong
struct sockaddr,_ saFamily as ushort,_ saData as char[14]
struct clisockaddr,_ saFamily as ushort,_ saData as char[14]
struct addrinfo,_ aiFlags as long,_ aiFamily as long,_ aiSocktype as long,_ aiProtocol as long,_ aiAddrlen as ulong,_ aiCanonname as ulong,_ aiAddr as ulong,_ aiNext as ulong
struct cliaddrinfo,_ aiFlags as long,_ aiFamily as long,_ aiSocktype as long,_ aiProtocol as long,_ aiAddrlen as ulong,_ aiCanonname as ulong,_ aiAddr as ulong,_ aiNext as ulong
struct lp,_ addrinfo as ulong
'addrinfo structure for hinting to getaddrinfo struct HINTS,_ aiFlags as long,_ aiFamily as long,_ aiSocktype as long,_ aiProtocol as long,_ aiAddrlen as ulong,_ aiCanonname as ulong,_ aiAddr as ulong,_ aiNext as ulong
struct SOCKET,_ lp as ulong
struct sockaddrin,_ sinFamily as short,_ sinPort as ushort,_ sinAddr as ulong,_ sinZero as char[8]
struct clisockaddrin,_ sinFamily as short,_ sinPort as ushort,_ sinAddr as ulong,_ sinZero as char[8]
HINTS.aiAddrlen.struct = 0 HINTS.aiAddr.struct = 0 HINTS.aiCanonname.struct = 0 HINTS.aiNext.struct = 0
HINTS.aiFlags.struct = 1 'AI_PASSIVE HINTS.aiFamily.struct = 2 'AF_INET HINTS.aiSocktype.struct = 2 'SOCK_DGRAM (Use UDP datagrams instead of TCP stream) HINTS.aiProtocol.struct = 17 'IPPROTO_UDP
'end return
[Botao1] s$="s0@" packet$ = "misturadora 1 " gosub [udp] gosub [estadosaídas] goto [start] wait
[Botao2] s$="s1@" packet$ = "misturadora 2" gosub [udp] gosub [estadosaídas] wait
[Botao3] s$="s2@" packet$ = "misturadora 3" gosub [udp] gosub [estadosaídas] wait
[Botao4] s$="s3@" packet$ = "misturadora 4" gosub [udp] gosub [estadosaídas] wait
[Botao5] TIMER 0 scan x=x+1
s$="s3s@" packet$ = "sequenciador s3s " gosub [udp] gosub [estadosaídas] if s$="s3s@" then print #main.3, "fill red" for y=0 to tempo
print y : print x : print time$() next y s$="s3r@" gosub [udp] gosub [estadosaídas] s$="s3r@" packet$ = "sequenciador s3r " gosub [udp] gosub [estadosaídas] if s$= "s0s@" then print #main.0, "fill red" for y=0 to tempo
print y : print x next y s$="s0s@" gosub [udp] gosub [estadosaídas] s$="s0s@" packet$ = "sequenciador s0s " gosub [udp] gosub [estadosaídas]
if s$= "s1s@" then print #main.1, "fill red" for y=0 to tempo
print y : print x next y s$="s0r@" packet$ = "sequenciador s0r "
gosub [udp] gosub [estadosaídas] s$="s0r@" packet$ = "sequenciador s0r " gosub [udp] gosub [estadosaídas] if s$= "s2s@" then print #main.2, "fill red" for y=0 to tempo
print y : print x next y s$="s2r@" gosub [udp] gosub [estadosaídas] s$="s1s@" packet$ = "sequenciador s1s " gosub [udp] gosub [estadosaídas] if s$= "s3s@" then print #main.3, "fill red" for y=0 to tempo
print y : print x : print time$() next y
gosub [estadosaídas] s$="s1r@" packet$ = "sequenciador " gosub [udp] if s$= "s0s@" then print #main.0, "fill red" for y=0 to tempo
print y : print x next y gosub [estadosaídas] s$="s2s@" packet$ = "sequenciador " gosub [udp] gosub [estadosaídas] if s$= "s3S@" then print #main.3, "fill red" for y=0 to tempo
print y : print x : print time$() next y
gosub [estadosaídas] s$="s2r@" packet$ = "sequenciador " gosub [udp] if s$= "s0@" then print #main.0, "fill red" for y=0 to tempo
print y : print x next y gosub [udp] gosub [estadosaídas] if temp<100 then goto [Botao5] else goto [start] wait ' acaba botoes [close]
close #main wait [estadosaídas] v=v+1 print "loop estado de saídas numero" , v print time$() scan
print #main.DataReceived, packet$ if s$= "s0@" then print #main.0, "fill red" if s$= "PLAY" then print #main.0, "fill red" if s$= "s0s@" then print #main.0, "fill red" if s$= "s0r@" then print #main.0, "fill black" if s$= "s0s@" then print #main.0, "fill red" print packet$ if s$= "s1@" then print #main.1, "fill red"
if s$= "s1s@" then print #main.1, "fill red" if s$= "s1r@" then print #main.1, "fill black" if RXdata$= "s1rs@" then print #main.1, "fill red" print packet$ if s$= "s2@" then print #main.2, "fill red" if s$= "s2s@" then print #main.2, "fill red" if s$= "s2r@" then print #main.2, "fill black" if s$= "s2r@" then print #main.2, "fill black" if RXdata$= "s2s@" then print #main.2, "fill red" if s$= "s3@" then print #main.3, "fill red" if s$= "s3s@" then print #main.3, "fill red" if s$= "s3r@" then print #main.3, "fill black"
if s$= "s3s@" then print #main.3, "fill red" if s$= "s3r@" then print #main.3, "fill black" scan
return wait [udp] return [fim] print "fim "
a = closesocket(sock) a = WSACleanup() call CloseWinsock scan
|
|
|
Post by Chris Iverson on Feb 8, 2021 13:05:52 GMT -5
I'm going to try to rewrite this example using a helper DLL that I made for network communications. The main thing to do to avoid blocking when doing a recv() is to check if the socket has data available to receive first, using a call like select(). EDIT: Well, here's a start. I'm not quite sure how this is supposed to operate, but I do get responses to and from this. I haven't tried public responses yet, as I'm not on a network that will allow that at the moment. This will require my LBNet DLL; you can download a zip file containing it on this page: github.com/iversc/lbnet/releases/tag/2.2.0-RC1[inicio] BackgroundColor$ = "blue" ForegroundColor$ = "red"
WindowWidth = DisplayWidth /1.25 WindowHeight = DisplayHeight /1.25 UpperLeftX = 0 UpperLeftY = 0 STATICTEXT #main.Label1, "Dados Recebidos", 4, 200, 100, 20
TEXTBOX #main.DataReceived, 4, 240, 150, 20 STATICTEXT #main.Label1, "Mensagem a enviar" , 4, 80, 100, 20 TEXTBOX #main.DataToSend, 4,100, 150, 20
BUTTON #main.send, "Enviar >>", [SendData],ul, 170, 100 ,200, 25 button #main.botao1, "botao1", [Botao1] ,ul, 400, 250 ,100, 75 BUTTON #main.botao2, "botao2", [Botao2] ,ul, 650, 250 ,100, 75 BUTTON #main.botao3, "botao3", [Botao3] ,ul, 900, 250 ,100, 75 BUTTON #main.botao4, "botao4", [Botao4] ,ul, 1150, 250 ,100, 75 BUTTON #main.botao5, "sequenciador 123", [Botao5] ,ul, 400, 550 ,100, 75 BUTTON #main.botao6, "reset sequenciador", [Botao6] ,ul, 525, 550 ,100, 75
STATICTEXT #main.credit, "By SPD ", 20, 160*2+30, 200, 30 graphicbox #main.0, 400, 50, 100, 100 graphicbox #main.1, 650, 50, 100, 100 graphicbox #main.2, 900, 50, 100, 100 graphicbox #main.3, 1150, 50, 100, 100 open "comunicação udp prototipo" for window as #main
print #main, "font ms_sans_serif 10" print #main, "trapclose [close]" print #main.DataReceived, "Dados a receber aparecem aqui..." print #main.DataToSend, "escreva a mensagem a enviar..." print #main.0, "home" 'center the pen print #main.0, "down" 'ready to draw print #main.0, "fill black" 'fill the graphics area black print #main.1, "home" 'center the pen print #main.1, "down" 'ready to draw print #main.1, "fill black" 'fill the graphics area black print #main.2, "home" 'center the pen print #main.2, "down" 'ready to draw print #main.2, "fill black" 'fill the graphics area black print #main.3, "home" 'center the pen print #main.3, "down" 'ready to draw print #main.3, "fill black" 'fill the graphics area black 'MAIN PROGRAM LOOP
[start] scan
Call OpenLBNetDLL port = 8888 sock = UDPCreateListenSocket(str$(port)) 'get start time [inicio2] startTime = time$("ms") print "startTime - " , startTime
while info$ <> "END" if UDPIsReadAvailable(sock, 0) = 0 then timer 100, [nextLoop] wait end if
bufSize = 1024 buf$ = space$(bufSize) udpFrom$ = "" recv = UDPReceiveFrom(sock, buf$, bufSize, udpFrom$) If recv < 0 then print "UDPReceive Error - ";GetError() a = UDPClose(sock) call CloseLBNetDLL end end if
info$ = left$(buf$, recv) s$ = info$ GOSUB [estadosaídas]
scan print info$
sendBuf$ = "testReturn" ret = UDPSendTo(sock, sendBuf$, len(sendBuf$), udpFrom$) if ret = -1 then print "Send error - ";GetError() end if
[nextLoop] timer 0 scan wend scan
'INSERT FUNCTIONS HERE
'==================== '==Helper Functions== '==================== Sub OpenLBNetDLL open "LBNet.dll" for DLL as #LBNet a = InitLBNet() End Sub
Sub CloseLBNetDLL a = EndLBNet() close #LBNet End Sub
Function InitLBNet() CallDLL #LBNet, "InitLBNet",_ InitLBNet as long End Function
Function EndLBNet() CallDLL #LBNet, "EndLBNet",_ EndLBNet as long End Function
Function IsSocketInvalid(sock) CallDLL #LBNet, "IsSocketInvalid",_ sock as ulong,_ IsSocketInvalid as long End Function
Function GetError() CallDLL #LBNet, "GetError",_ GetError as long
if GetError < 0 then GetError = (abs(GetError) XOR hexdec("FFFFFFFF")) + 1 end if End Function
Function UDPConnect(host$, srv$, msTimeout) CallDLL #LBNet, "UDPConnect",_ host$ as ptr,_ srv$ as ptr,_ msTimeout as long,_ UDPConnect as long End Function
Function UDPSend(udpSock, buf$, bufLen) CallDLL #LBNet, "UDPSend",_ udpSock as long,_ buf$ as ptr,_ bufLen as long,_ 0 as long,_ UDPSend as long End Function
Function UDPSendTo(udpSock, buf$, bufLen, udpInfo$) CallDLL #LBNet, "UDPSend",_ udpSock as long,_ buf$ as ptr,_ bufLen as long,_ udpInfo$ as ptr,_ UDPSendTo as long End Function
Function UDPClose(udpSock) CallDLL #LBNet, "UDPClose",_ udpSock as long,_ UDPClose as long End Function
Function UDPGetInfoSize() CallDLL #LBNet, "UDPGetInfoSize",_ UDPGetInfoSize as long End Function
Function UDPReceive(udpSock, byref buf$, bufLen) CallDLL #LBNet, "UDPReceive",_ udpSock as long,_ buf$ as ptr,_ bufLen as long,_ 0 as long,_ UDPReceive as long End Function
Function UDPReceiveFrom(udpSock, byref buf$, bufLen, byref udpFrom$) udpFrom$ = space$(UDPGetInfoSize())
CallDLL #LBNet, "UDPReceive",_ udpSock as long,_ buf$ as ptr,_ bufLen as long,_ udpFrom$ as ptr,_ UDPReceiveFrom as long End Function
Function UDPIsReadAvailable(udpSock, msTimeout) CallDLL #LBNet, "UDPIsReadAvailable",_ udpSock as long,_ msTimeout as long,_ UDPIsReadAvailable as long End Function
Function UDPCreateListenSocket(pService$) CallDLL #LBNet, "UDPCreateListenSocket",_ pService$ as ptr,_ UDPCreateListenSocket as long End Function
Function UDPGetRemoteIP$(udpInfo$) UDPGetRemoteIP$ = ""
CallDLL #LBNet, "UDPGetRemoteIP",_ udpInfo$ as ptr,_ ret as ulong
If ret <> 0 then UDPGetRemoteIP$ = winstring(ret) End Function
Function UDPGetRemotePort(udpInfo$) CallDLL #LBNet, "UDPGetRemotePort",_ udpInfo$ as ptr,_ UDPGetRemotePort as long End Function
[Botao1] s$="s0@" packet$ = "misturadora 1 " gosub [udp] gosub [estadosaídas] 'goto [start] wait
[Botao2] s$="s1@" packet$ = "misturadora 2" gosub [udp] gosub [estadosaídas] wait
[Botao3] s$="s2@" packet$ = "misturadora 3" gosub [udp] gosub [estadosaídas] wait
[Botao4] s$="s3@" packet$ = "misturadora 4" gosub [udp] gosub [estadosaídas] wait
[Botao5] TIMER 0 scan x=x+1
s$="s3s@" packet$ = "sequenciador s3s " gosub [udp] gosub [estadosaídas] if s$="s3s@" then print #main.3, "fill red" for y=0 to tempo
print y : print x : print time$() next y s$="s3r@" gosub [udp] gosub [estadosaídas] s$="s3r@" packet$ = "sequenciador s3r " gosub [udp] gosub [estadosaídas] if s$= "s0s@" then print #main.0, "fill red" for y=0 to tempo
print y : print x next y s$="s0s@" gosub [udp] gosub [estadosaídas] s$="s0s@" packet$ = "sequenciador s0s " gosub [udp] gosub [estadosaídas]
if s$= "s1s@" then print #main.1, "fill red" for y=0 to tempo
print y : print x next y s$="s0r@" packet$ = "sequenciador s0r "
gosub [udp] gosub [estadosaídas] s$="s0r@" packet$ = "sequenciador s0r " gosub [udp] gosub [estadosaídas] if s$= "s2s@" then print #main.2, "fill red" for y=0 to tempo
print y : print x next y s$="s2r@" gosub [udp] gosub [estadosaídas] s$="s1s@" packet$ = "sequenciador s1s " gosub [udp] gosub [estadosaídas] if s$= "s3s@" then print #main.3, "fill red" for y=0 to tempo
print y : print x : print time$() next y
gosub [estadosaídas] s$="s1r@" packet$ = "sequenciador " gosub [udp] if s$= "s0s@" then print #main.0, "fill red" for y=0 to tempo
print y : print x next y gosub [estadosaídas] s$="s2s@" packet$ = "sequenciador " gosub [udp] gosub [estadosaídas] if s$= "s3S@" then print #main.3, "fill red" for y=0 to tempo
print y : print x : print time$() next y
gosub [estadosaídas] s$="s2r@" packet$ = "sequenciador " gosub [udp] if s$= "s0@" then print #main.0, "fill red" for y=0 to tempo
print y : print x next y gosub [udp] gosub [estadosaídas] if temp<100 then goto [Botao5] else goto [start] wait ' acaba botoes [close]
close #main wait [estadosaídas] v=v+1 print "loop estado de saídas numero" , v print time$() scan
print #main.DataReceived, packet$ if s$= "s0@" then print #main.0, "fill red" if s$= "PLAY" then print #main.0, "fill red" if s$= "s0s@" then print #main.0, "fill red" if s$= "s0r@" then print #main.0, "fill black" if s$= "s0s@" then print #main.0, "fill red" print packet$ if s$= "s1@" then print #main.1, "fill red"
if s$= "s1s@" then print #main.1, "fill red" if s$= "s1r@" then print #main.1, "fill black" if RXdata$= "s1rs@" then print #main.1, "fill red" print packet$ if s$= "s2@" then print #main.2, "fill red" if s$= "s2s@" then print #main.2, "fill red" if s$= "s2r@" then print #main.2, "fill black" if s$= "s2r@" then print #main.2, "fill black" if RXdata$= "s2s@" then print #main.2, "fill red" if s$= "s3@" then print #main.3, "fill red" if s$= "s3s@" then print #main.3, "fill red" if s$= "s3r@" then print #main.3, "fill black"
if s$= "s3s@" then print #main.3, "fill red" if s$= "s3r@" then print #main.3, "fill black" scan
return wait [udp] return [fim] print "fim "
a = UDPClose(sock) call CloseLBNetDLL scan
|
|
Tasp
Full Member
Posts: 215
|
Post by Tasp on Feb 10, 2021 14:24:33 GMT -5
OOOOOOOO!
New version!
Don't suppose you've had the opportunity to write up any docs for it?
|
|
|
Post by Chris Iverson on Feb 10, 2021 15:27:06 GMT -5
No, not yet, sadly. I initially intended to change the error codes used before writing docs, but I think I may just skip that for now.
I'll get a doc written up.
|
|
|
Post by zxrportugal on Feb 11, 2021 17:35:35 GMT -5
hi i´m sorry doesn´t work for me , no comunication.....the program opens but no comunication..... with your other server/client example programs the same.... the LBNet file is in the lb folder and in windows system32 and system folder . regards
|
|
|
Post by Chris Iverson on Feb 12, 2021 2:26:42 GMT -5
That's definitely odd. Some dropped packets, I might expect(it IS UDP, after all), but to not work at all? Tasp You'll be happy to note that I've started to kick myself into gear when it comes to documentation. I've begun documenting the DLL here: github.com/iversc/lbnet/blob/master/docs/TCP-UDP.mdFull descriptions of all my functions relating to TCP and UDP communication are already there, and I'm planning an overview section that goes over how sockets are meant to work, and ties it all together. (Note that the documentation on that page is going over my wrapper functions in the WrapperFunctions.bas file, and not the straight DLL calls themselves.) I'll have a separate page documenting TLS stuff.
|
|
|
Post by zxrportugal on Feb 12, 2021 16:28:58 GMT -5
hi Chris in my pc doesn´t work in Lan, tryed to stop the anti virus and the windows firewall, but nothing...
|
|
|
Post by zxrportugal on Feb 16, 2021 4:51:22 GMT -5
sending udp messages on Lan working well, not mine i think was writen by BRENT THORN , i add a infinite loop
[inicio] y=y+1 open "WS2_32" for DLL as #winsock calldll #winsock, "WSACleanup", ret as long packet$ = str$(y) ok = UDPsend("192.168.1.99", 9998, packet$)
if ok then print "Packet sent" else print "UDPsend failed"
for x=1 to 100 print x next x scan
goto [inicio]
end
function UDPsend(addr$, port, msg$) AF.INET = 2 SOCK.DGRAM = 2 IPPROTO.UDP = 17 UDPsend = 0 port = (port and hexdec("FF00")) / 256 + (port and 255) * 256 ' swap bytes calldll #winsock, "inet_addr", addr$ as ptr, ipaddr as ulong struct WSAdata, d as char[398] calldll #winsock, "WSAStartup", 514 as long, WSAdata as struct, ret as long if ret then exit function calldll #winsock, "socket", AF.INET as long, SOCK.DGRAM as long, _ IPPROTO.UDP as long, socket as long if socket = -1 then exit function struct addr, family as short, port as short, addr as ulong, zero as char[8] addr.family.struct = AF.INET addr.port.struct = port addr.addr.struct = ipaddr al = len(addr.struct) ml = len(msg$) calldll #winsock, "sendto", socket as long, msg$ as ptr, ml as long, _ 0 as long, addr as struct, al as long, sent as long calldll #winsock, "closesocket", socket as long, ret as long calldll #winsock, "WSACleanup", ret as long if sent = ml then UDPsend = 1 end function
|
|
|
Post by zxrportugal on Feb 24, 2021 14:38:18 GMT -5
hi Chris After a install of a windows 10 and liberty basic version 4.5.1 i can confirm that In LAN and with android app your version works !!!! good news !!!! tested with hi speed botton press and no problems.... ! will give a try on WAN ! Best Regards
|
|