$INCLUDE "RAPIDQ.INC"
DECLARE FUNCTION CreateThread LIB "kernel32" ALIAS "CreateThread" (lpThreadAttributes AS LONG, BYVAL dwStackSize AS LONG, lpStartAddress AS LONG, lpParameter AS LONG, BYVAL dwCreationFlags AS LONG, lpThreadId AS LONG) AS LONG
DECLARE FUNCTION CloseHandle LIB "kernel32" ALIAS "CloseHandle" (BYVAL hObject AS LONG) AS LONG
DECLARE SUB Sleepw LIB "kernel32" ALIAS "Sleep" (BYVAL dwMilliseconds AS LONG)
DECLARE FUNCTION TerminateThread LIB "kernel32" ALIAS "TerminateThread" (BYVAL hThread AS LONG, BYVAL dwExitCode AS LONG) AS LONG
DECLARE SUB thread
DECLARE SUB essai(sender AS QBUTTON)
DECLARE SUB essai1(sender AS QBUTTON)
DECLARE SUB essai2(sender AS QBUTTON)
DIM drap AS INTEGER
DIM numSock AS INTEGER
DIM numSock1 AS INTEGER
DIM hThread AS LONG
CREATE Form AS QFORM
CAPTION = "Creation de thread"
Width = 320
Height = 240
Center
CREATE Sock AS QSOCKET
Protocol=17
TYPE=2
END CREATE
CREATE Button1 AS QBUTTON
CAPTION = "Lancer le Thread"
Left = 152
Top = 11
width=120
onclick = essai
END CREATE
CREATE Button2 AS QBUTTON
CAPTION = "Arreter le Thread"
Left = 152
Top = 35
width=120
onclick = essai1
END CREATE
CREATE Button3 AS QBUTTON
CAPTION = "Delta T"
Left = 152
Top = 60
width=120
onclick = essai2
END CREATE
CREATE Edit1 AS QEDIT
Text = "Edit1"
Left = 15
Top = 16
TabOrder = 9
END CREATE
CREATE Edit2 AS QEDIT
Text = "Edit1"
Left = 15
Top =36
TabOrder = 9
END CREATE
CREATE Edit3 AS QEDIT
Text = "Edit1"
Left = 15
Top = 56
TabOrder = 9
END CREATE
CREATE Edit4 AS QEDIT
Text = "Edit1"
Left = 15
Top = 76
TabOrder = 9
END CREATE
END CREATE
Form.SHOWMODAL
SUB essai
DIM lpThreadId AS LONG
DIM test AS LONG
DIM ptrt AS LONG
ptrt=VARPTR(lpThreadId)
Add = CODEPTR(thread)
numSock = Sock.Connect("191.9.202.255", 1963)
numSock1=sock.OPEN(1970)
hThread= CreateThread (BYVAL 0&,BYVAL 0&, Add , BYVAL 0&, BYVAL 0&, ptrt )
edit3.text=STR$(hThread)
END SUB
SUB essai1
DIM ess AS LONG
DIM test AS LONG
ess =TerminateThread(hThread, 0)
test=CloseHandle(hThread)
sock.writeline(numsock,"fin")
sock.CLOSE(numsock)
sock.CLOSE(numsock1)
END SUB
SUB thread
DIM t1 AS SINGLE
DIM este AS STRING*255
DIM i AS INTEGER
drap=0
WHILE drap=0
IF sock.IsServerReady(numSock1)=true THEN
edit1.text= Sock.READ(numSock1,32000)
edit2.text = sock.Gethostip
END IF
sleepw(1)
sock.write(numsock,STR$(TIMER)+" de T0",LEN(STR$(TIMER))+6)
edit3.text=STR$(TIMER-t1)
t1=TIMER
WEND
END SUB
SUB essai2
edit4.text=STR$(VAL(edit3.text)*1000) & " ms"
END SUB
|