Pbm d envoi de donnée en socket

Résolu
cs_jhd Messages postés 338 Date d'inscription mardi 13 août 2002 Statut Membre Dernière intervention 29 novembre 2007 - 3 oct. 2005 à 23:59
cs_jhd Messages postés 338 Date d'inscription mardi 13 août 2002 Statut Membre Dernière intervention 29 novembre 2007 - 4 oct. 2005 à 13:16
voila je n arrive pas a envoyer des données ligne par ligne du serveur vers le client. celle ci s ajoute les une au autre et lorsque je les recois coté client elle sont sur une seule ligne.

voici le code server:
Private Sub cmdtmp_Click()
' Nom de l ordi
Dim dwLen As Long
Dim strString As String
dwLen = MAX_COMPUTERNAME_LENGTH + 1
strString = String(dwLen, "X")
GetComputerName strString, dwLen
strString = Left(strString, dwLen)
' formServer.winsock.SendData ("?PCinfo Nom PC: " & strString & vbNewLine)
' Nom de l Utilisateur
dwLen = MAX_COMPUTERNAME_LENGTH + 1
strString = String(dwLen, "X")
GetUserName strString, dwLen
strString = Left(strString, dwLen)
' formServer.winsock.SendData ("?PCinfo Nom Utilisateur: " & strString & vbNewLine)
' Version de windows
Dim OSInfo As OSVERSIONINFO, PId As String
OSInfo.dwOSVersionInfoSize = Len(OSInfo)
'Get the Windows version
Ret& = GetVersionEx(OSInfo)
'Chack for errors
If Ret& = 0 Then End
'Print the information to the form
Select Case OSInfo.dwPlatformId
Case 0
PId = "Windows 32s "
Case 1
PId = "Windows 95/98"
Case 2
PId = "Windows NT "
End Select
' formServer.winsock.SendData ("?PCinfo OS: " & PId & vbNewLine)
' formServer.winsock.SendData ("?PCinfo Win version: " & Str$(OSInfo.dwMajorVersion) + "." + LTrim(Str(OSInfo.dwMinorVersion)) & vbNewLine)
' formServer.winsock.SendData ("?PCinfo Build: " & Str(OSInfo.dwBuildNumber) & vbNewLine)
End Sub

et le code cote client:
Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
Dim buffer As String
buffer = Space(512)
winsock.GetData buffer, vbNewLine
txtTmp.Text = txtTmp.Text & buffer & vbNewLine
Dim varTrigger() As String ' tableau coupant chaq mots
Dim varTmp As String
varTrigger = Split(buffer, Chr(32))
If (StrComp(varTrigger(0), "?Password") = 0) Then
Dim varPassword As String
varPassword = InputBox("Entrez le mot de passe", "Identification au serveur")
winsock.SendData "$Password " & varPassword
ElseIf (StrComp(varTrigger(0), "?PassOK") = 0) Then
fctShowMenu
ElseIf (StrComp(varTrigger(0), "?PCinfo") = 0) Then
varTmp = Mid(buffer, InStr(1, buffer, " "))
formPCinfo.txtInfoPC.Text = formPCinfo.txtInfoPC.Text & varTmp
End If
End Sub

en plus je ne recoi que les deux premier winsock.sendata sur une seule ligne.

Merci de votre aide
www.jhdcript.com ( Tout N Est Qu Une illuSion )

6 réponses

PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
4 oct. 2005 à 13:10
re,
"a tout hasard pkoi coté client on utilise pas"
bah parce que coté client, ta form ne s'appelle pas formServer
rien ne t'empêche d'utiliser cette même fonction (c'est pour çà que je l'ai déclaré en Public, à toi d'adapter le nom du Winsock concerné)

pour ton dernier problème, essai (sans certitude) de remplacer, dans cmd_tmp, partie nom d'utilisateur
strString = Left (strString, dwLen)
par
strString = Left(strString, dwLen) & chr(32)

et sans rapport, mais il me semble que tu as fait aussi une erreur en case 1 du PId. (manque aussi un espace)

PCPT
3
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 47
4 oct. 2005 à 01:28
salut

bah ouai, normal, tu ne laisses pas de temps entre tes envoies


Public Function SendDataSock(WSK As Winsock, sChaine As String) As Boolean
'
'à utiliser de la manière suivante :
' call SendDataSock(formServer.winsock, "MonMessageSansLeSeparateurFinal")
'
'
'oubien :
' VariableBoolean = SendDataSock(formServer.winsock, "MonMessageSansLeSeparateurFinal")
'
'pour ainsi tester si besoin si le Socket est bien toujours connecté
'
'
If WSK.State <> 7 Then
SendDataSock = False
Else
WSK.SendData sChaine & vbNewLine
DoEvents '<- c'est lui qui donne la main au système, et permet la séparation
' de 2 envoies consécutifs
SendDataSock = True
End If
End Function

' --------------------
' voici le code server:
' --------------------
'
'
Private Sub cmdtmp_Click()
' Nom de l ordi
Dim dwLen As Long
Dim strString As String
dwLen = MAX_COMPUTERNAME_LENGTH + 1
strString = String (dwLen, "X")
GetComputerName strString, dwLen
strString = Left(strString, dwLen)
'
'<MODIF>
'formServer.winsock.SendData ("?PCinfo Nom PC: " & strString & vbNewLine)
Call SendDataSock(formServer.Winsock, "?PCinfo Nom PC: " & strString)
'</MODIF>

' Nom de l Utilisateur
dwLen = MAX_COMPUTERNAME_LENGTH + 1
strString = String (dwLen, "X")
GetUserName strString, dwLen
strString = Left(strString, dwLen)
'
'<MODIF>
'formServer.winsock.SendData ("?PCinfo Nom Utilisateur: " & strString & vbNewLine)
Call SendDataSock(formServer.Winsock, "?PCinfo Nom Utilisateur: " & strString)
'</MODIF>

' Version de windows
Dim OSInfo As OSVERSIONINFO, PId As String
OSInfo.dwOSVersionInfoSize = Len (OSInfo)
'Get the Windows version
Ret& = GetVersionEx(OSInfo)
'Chack for errors
If Ret& = 0 Then End
'Print the information to the form
Select Case OSInfo.dwPlatformId
Case 0
PId = "Windows 32s "
Case 1
PId = "Windows 95/98"
Case 2
PId = "Windows NT "
End Select
'
'<MODIF>
'formServer.winsock.SendData ("?PCinfo OS: " & PId & vbNewLine)
'formServer.winsock.SendData ("?PCinfo Win version: " & Str$(OSInfo.dwMajorVersion) + "." + LTrim(Str(OSInfo.dwMinorVersion)) & vbNewLine)
'formServer.winsock.SendData ("?PCinfo Build: " & Str(OSInfo.dwBuildNumber) & vbNewLine)
Call SendDataSock(formServer.Winsock, "?PCinfo OS: " & PId)
Call SendDataSock(formServer.Winsock, "?PCinfo Win version: " & Str$(OSInfo.dwMajorVersion) + "." + LTrim (Str(OSInfo.dwMinorVersion)))
Call SendDataSock(formServer.Winsock, "?PCinfo Build: " & Str(OSInfo.dwBuildNumber))
'</MODIF>

End Sub

' ----------------------
' et le code cote client:
' ----------------------
'
'
Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
Dim buffer As String
buffer = Space(512)
Winsock.GetData buffer, vbNewLine
txtTmp.Text = txtTmp.Text & buffer & vbNewLine
Dim varTrigger() As String ' tableau coupant chaq mots
Dim varTmp As String
varTrigger = Split (buffer, Chr(32))
If (StrComp(varTrigger(0), "?Password") = 0) Then
Dim varPassword As String
varPassword = InputBox("Entrez le mot de passe", "Identification au serveur")
Winsock.SendData "$Password " & varPassword
ElseIf ( StrComp (varTrigger(0), "?PassOK") = 0) Then
fctShowMenu
ElseIf (StrComp(varTrigger(0), "?PCinfo") = 0) Then
varTmp = Mid (buffer, InStr(1, buffer, " "))
formPCinfo.txtInfoPC.Text = formPCinfo.txtInfoPC.Text & varTmp
End If
End Sub



<SMALL> Coloration syntaxique automatique [AFCK]</SMALL>


PCPT
0
cs_jhd Messages postés 338 Date d'inscription mardi 13 août 2002 Statut Membre Dernière intervention 29 novembre 2007
4 oct. 2005 à 08:48
je n ai qu une chose a dire merci mec :)

www.jhdcript.com ( Tout N Est Qu Une illuSion )
0
cs_jhd Messages postés 338 Date d'inscription mardi 13 août 2002 Statut Membre Dernière intervention 29 novembre 2007
4 oct. 2005 à 09:01
a tout hasard pkoi coté client on utilise pas
Call SendDataSock(formServer.Winsock, "$Password " & varPassword )

a la place de
Winsock.SendData "$Password " & varPassword

j ai essayer et ca ne mùarche pas
www.jhdcript.com ( Tout N Est Qu Une illuSion )
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
cs_jhd Messages postés 338 Date d'inscription mardi 13 août 2002 Statut Membre Dernière intervention 29 novembre 2007
4 oct. 2005 à 09:21
a oui g encore une petite erreur
ca m affiche cela

Nom PC: EXIA-JCESTEVEZ1
Nom Utilisateur: jcestevez OS: Windows NT
Win version: 5.1
Build: 2600

au lieu de

Nom PC: EXIA-JCESTEVEZ1
Nom Utilisateur: jcestevez
OS: Windows NT
Win version: 5.1
Build: 2600

et jvois vrement pas d ou ca vien

www.jhdcript.com ( Tout N Est Qu Une illuSion )
0
cs_jhd Messages postés 338 Date d'inscription mardi 13 août 2002 Statut Membre Dernière intervention 29 novembre 2007
4 oct. 2005 à 13:16
merci mec :)

www.jhdcript.com ( Tout N Est Qu Une illuSion )
0
Rejoignez-nous