OVH Cloud OVH Cloud

Winsock

2 réponses
Avatar
jose MULLER
Bonjour

Je dois interfacer en client sous VB6 une camera qui est gérée par un
programme Serveur.

1) J'utilise winsock pour me connecter au programme serveur

Private Sub cmdClient_Click()
'------------------------

Me.Winsock1.RemoteHost = "127.0.0.1"
Me.Winsock1.RemotePort = 3000
Me.Winsock1.Protocol = sckTCPProtocol
Me.Winsock1.LocalPort = 0

Me.Winsock1.Connect

Memo.Text = Memo.Text & "cmdClient" & vbCrLf

End Sub


c'est OK , le programme serveur me répond correctement

2) Je lance ma premiere commande et le programme serveur doit me répondre
par l'envoi d une structure

Private Sub cmd_PRTC_INIT_HARDWARE_Click()
'----------------------------------------
Dim sTmp As String

' envoi de la commande
Memo.Text = Memo.Text & "PRTC_INIT_HARDWARE" & vbCrLf
Me.Winsock1.SendData PRTC_INIT_HARDWARE

' la structure status en retour
' Me.Winsock1.GetData ServerStatus, , Len(ServerStatus) ??????????
' Me.Winsock1.GetData sTmp ',type,maxLen ????????????
' Debug.Print Len(sTmp)
?????????????
' Memo.Text = Memo.Text & sTmp & vbCrLf & "---------" & vbCrLf

End Sub

Type TCServerStatus
m_ErrorCode As Long
m_Info1 As Long
m_Info2 As Long
m_Status As Long
m_Length As Long
End Type

Public ServerStatus As TCServerStatus

--------------

en plus m_ErrorCode = 0 = NO_ERROR

Je ne recois aucune réponse si j'utilise Private Sub
Winsock1_DataArrival(ByVal bytesTotal As Long)


Comment envoyer et recevoir une structure ??????????

merci

2 réponses

Avatar
Sauf erreur de ma part, je ne panse pas qu'il soit
possible de recevoir la structure en une seule fois.
If faut utiliser :

Winsock.GetData Struct.Champ1,vbLong
Winsock.getdata Struct.Champ2,vbInteger
etc...

-----Message d'origine-----
Bonjour

Je dois interfacer en client sous VB6 une camera qui est


gérée par un
programme Serveur.

1) J'utilise winsock pour me connecter au programme


serveur

Private Sub cmdClient_Click()
'------------------------

Me.Winsock1.RemoteHost = "127.0.0.1"
Me.Winsock1.RemotePort = 3000
Me.Winsock1.Protocol = sckTCPProtocol
Me.Winsock1.LocalPort = 0

Me.Winsock1.Connect

Memo.Text = Memo.Text & "cmdClient" & vbCrLf

End Sub


c'est OK , le programme serveur me répond correctement

2) Je lance ma premiere commande et le programme serveur


doit me répondre
par l'envoi d une structure

Private Sub cmd_PRTC_INIT_HARDWARE_Click()
'----------------------------------------
Dim sTmp As String

' envoi de la commande
Memo.Text = Memo.Text & "PRTC_INIT_HARDWARE" & vbCrLf
Me.Winsock1.SendData PRTC_INIT_HARDWARE

' la structure status en retour
' Me.Winsock1.GetData ServerStatus, , Len


(ServerStatus) ??????????
' Me.Winsock1.GetData


sTmp ',type,maxLen ????????????
' Debug.Print Len(sTmp)
?????????????
' Memo.Text = Memo.Text & sTmp & vbCrLf & "---------"


& vbCrLf

End Sub

Type TCServerStatus
m_ErrorCode As Long
m_Info1 As Long
m_Info2 As Long
m_Status As Long
m_Length As Long
End Type

Public ServerStatus As TCServerStatus

--------------

en plus m_ErrorCode = 0 = NO_ERROR

Je ne recois aucune réponse si j'utilise Private Sub
Winsock1_DataArrival(ByVal bytesTotal As Long)


Comment envoyer et recevoir une structure ??????????

merci




.



Avatar
Zoury
Bonjour! :O)

Il est possible d'envoyer la structure d'un coup sous forme de tableau de
Byte grace à l'api CopyMemory.. Voici exemple montrant comment
envoyer/recevoir les données :

Ajouter ces déclarations dans le haut du module :
'***
Private Type POINTAPI
x As Long
y As Long
End Type

Private Declare Sub CopyMemory _
Lib "kernel32" _
Alias "RtlMoveMemory" _
( _
ByRef pDst As Any, _
ByRef pSrc As Any, _
ByVal ByteLen As Long _
)
'***

Pour envoyer la structure
'***
Dim by() As Byte
Dim pt As POINTAPI

' initialise le point a envoyé
pt.x = 4
pt.y = 5

' dimensionne le tableau de byte
ReDim by(LenB(pt) - 1) As Byte

' copy le contenu du POINTAPI dans le tableau de byte
Call CopyMemory(by(0), pt, LenB(pt))

' envoi les données au serveur
Call wsClient.SendData(by)
'***

Pour la relire
'***
Private Sub wsServer_DataArrival(ByVal bytesTotal As Long)

Dim pt As POINTAPI
Dim by() As Byte

' initialise le tableau de byte
ReDim by(bytesTotal - 1) As Byte

' rempli notre tableau de byte avec les données reçues
Call wsServer.GetData(by, vbByte + vbArray, bytesTotal)

' on copie les données dans notre structure
Call CopyMemory(pt, by(0), bytesTotal)

' on imprime les valeurs de la structure
Debug.Print pt.x, pt.y

End Sub
'***


--
Cordialement
Yanick Lefebvre - MVP pour Visual Basic
http://faq.vb.free.fr/?rubrique=0 - http://www.mvps.org/vbnet/
http://www.mentalis.org/agnet/apiguide.shtml - http://www.mztools.com/

a écrit dans le message de
news:1a3bc01c44e1e$e918ab70$
Sauf erreur de ma part, je ne panse pas qu'il soit
possible de recevoir la structure en une seule fois.
If faut utiliser :

Winsock.GetData Struct.Champ1,vbLong
Winsock.getdata Struct.Champ2,vbInteger
etc...

-----Message d'origine-----
Bonjour

Je dois interfacer en client sous VB6 une camera qui est


gérée par un
programme Serveur.

1) J'utilise winsock pour me connecter au programme


serveur

Private Sub cmdClient_Click()
'------------------------

Me.Winsock1.RemoteHost = "127.0.0.1"
Me.Winsock1.RemotePort = 3000
Me.Winsock1.Protocol = sckTCPProtocol
Me.Winsock1.LocalPort = 0

Me.Winsock1.Connect

Memo.Text = Memo.Text & "cmdClient" & vbCrLf

End Sub


c'est OK , le programme serveur me répond correctement

2) Je lance ma premiere commande et le programme serveur


doit me répondre
par l'envoi d une structure

Private Sub cmd_PRTC_INIT_HARDWARE_Click()
'----------------------------------------
Dim sTmp As String

' envoi de la commande
Memo.Text = Memo.Text & "PRTC_INIT_HARDWARE" & vbCrLf
Me.Winsock1.SendData PRTC_INIT_HARDWARE

' la structure status en retour
' Me.Winsock1.GetData ServerStatus, , Len


(ServerStatus) ??????????
' Me.Winsock1.GetData


sTmp ',type,maxLen ????????????
' Debug.Print Len(sTmp)
?????????????
' Memo.Text = Memo.Text & sTmp & vbCrLf & "---------"


& vbCrLf

End Sub

Type TCServerStatus
m_ErrorCode As Long
m_Info1 As Long
m_Info2 As Long
m_Status As Long
m_Length As Long
End Type

Public ServerStatus As TCServerStatus

--------------

en plus m_ErrorCode = 0 = NO_ERROR

Je ne recois aucune réponse si j'utilise Private Sub
Winsock1_DataArrival(ByVal bytesTotal As Long)


Comment envoyer et recevoir une structure ??????????

merci




.