Guidance
指路人
g.yi.org
software / rapidq / Examples / Memory Process Thread Message / Thread / thread1.bas

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
' Copy and paste into your program
'exemples de gestion de socket en UDP
'Adresse de port 1970 et 1963


     $INCLUDE "RAPIDQ.INC"

'APIs
     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

'Subs Interne
     DECLARE SUB thread
     DECLARE SUB essai(sender AS QBUTTON)
     DECLARE SUB essai1(sender AS QBUTTON)
     DECLARE SUB essai2(sender AS QBUTTON)

'les Globales
     DIM drap AS INTEGER
     DIM numSock AS INTEGER
     DIM numSock1 AS INTEGER
     DIM hThread AS LONG




'Construction de la fenêtre

     CREATE Form AS QFORM
      CAPTION = "udp avec thread ->1970 <-1963"
      Width = 320
      Height = 240
      Center
      CREATE Sock AS QSOCKET
     'création du socket en mode UDP
       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
'Lance le thread de lecture
      DIM lpThreadId AS LONG
      DIM test AS LONG
      DIM ptrt AS LONG
'init des params
      ptrt=VARPTR(lpThreadId)
      Add = CODEPTR(thread)
'ouvre la socket(191.9.202.255) broadcast à modifier en fonction de votre configuration
      numSock = Sock.Connect("191.9.202.255", 1970)
'port reception
      numSock1=sock.OPEN(1963)
'creation du thread
      hThread= CreateThread (BYVAL 0&,BYVAL 0&, Add , BYVAL 0&, BYVAL 0&, ptrt )
      edit3.text=STR$(hThread)
     END SUB

     SUB essai1
'ferme le thread
      DIM ess AS LONG
      DIM test AS LONG
      ess =TerminateThread(hThread, 0)
      test=CloseHandle(hThread)
'ferme la socket
      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
'lecture de la socket en continu
       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 T1",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
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Wed 2022-9-28  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-05-14 16:02:56