Guidance
指路人
g.yi.org
software / rapidq / Examples / Memory Process Thread Message / Thread / thread.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 = "Creation de thread"
      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 mode brodcast xxx.xxx.xxx.255
'Changer l'adresse IP en fonction de la votre
'envoi vers un seul PC IP= 191.9.202.51 a titre d'exemple
      numSock = Sock.Connect("191.9.202.255", 1963)
'port reception
      numSock1=sock.OPEN(1970)
'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
     'boucle infini
      WHILE drap=0
'lecture de la socket
       IF sock.IsServerReady(numSock1)=true THEN
        edit1.text= Sock.READ(numSock1,32000)
        edit2.text = sock.Gethostip
       END IF
          'afin de ne pas manger du temps Process
       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
'sauve garde de edit3 en ms
      edit4.text=STR$(VAL(edit3.text)*1000) & " ms"
     END SUB
掌柜推荐
 
 
¥860.00 ·
 
 
¥900.00 ·
 
 
¥810.00 ·
 
 
¥317.00 ·
 
 
¥1,370.00 ·
 
 
¥660.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2002-05-14 16:00:28