Debuggage winsock vb6.0

Résolu
annehuart Messages postés 2 Date d'inscription vendredi 16 septembre 2005 Statut Membre Dernière intervention 21 septembre 2005 - 21 sept. 2005 à 11:14
PCPT Messages postés 13272 Date d'inscription lundi 13 décembre 2004 Statut Membre Dernière intervention 3 février 2018 - 21 sept. 2005 à 13:33
Est-ce que quelqu'un peut m'aider, svp...
Je suis en train de bosser sur un petit programme pour créer un client telnet.
J'ai des petits soucis avec la reconnexion ( on se connecte , on se déconnecte et c'est quand on veut a nouveau se connecter ke ca bug ). En fait mon programme marche, mais lorque j'enlève un des msg box , ben ca marche plus


Je vous joins le code que j'ai fait :

Dim host As String
Dim port As String
Dim connecte As Boolean 'pour savoir si le client est connecté ou non
Dim taskcmd(1 To 5000) As String 'variable contenant la position courante dans le script a executer
Dim ind As Integer
Dim commande(0 To 100) As String
Dim sckData As String


Dim j
Dim cmdi As Integer


Private Sub cmdSend_Click()


txtRep.Text = txtRep.Text & ">" & txtComm.Text & vbCrLf
txtRep.SelStart = Len(txtRep.Text)


SendCmd txtComm.Text


txtComm.Text = ""
txtComm.SetFocus


End Sub


Private Sub SendCmd(strsnd As String)
Winsock1.SendData strsnd
'chaque commande doit finir par le retour chariot...
Winsock1.SendData vbCrLf


End Sub
Private Sub cmdStartTelnet_Click()
host = txtAdIP.Text
port = txtPort.Text


' On Error Resume Next


MsgBox "winsock state :" & Winsock1.State
Winsock1.Close
Form1.Winsock1.RemoteHost = host
Form1.Winsock1.RemotePort = port
Form1.Winsock1.Connect
' MsgBox " connecte apres connect : " & connecte


End Sub


Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
End Sub


Private Sub winsock1_Connect()
MsgBox (" connexion réussie!")
connecte = True
End Sub


Private Sub cmdStopTelnet_Click()
Winsock1.Close
connecte = False
txtRep.Text = ""
End Sub


Private Sub Form_Load()
connecte = False
j = 1
cmdi = 1
End Sub


Private Sub Timer2_Timer()
'certain controles ne doivent pas etre accessible si l'utilisateur n'est pas connecté
If connecte = False Then
txtRep.Text = ""
txtComm.Enabled = False
cmdStopTelnet.Enabled = False
cmdSend.Enabled = False
cmdStartTelnet.Enabled = True


Else
cmdStopTelnet.Enabled = True
txtComm.Enabled = True
cmdStartTelnet.Enabled = False
cmdSend.Enabled = True


End If
End Sub



Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
' On Error Resume Next
' MsgBox "connecte =" & connecte
If connecte = True Then
Winsock1.GetData sckData
MsgBox sckData
txtRep.Text = txtRep.Text & sckData
txtRep.SelStart = Len(txtRep.Text)
End If


End Sub



Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
'interception des erreurs
MsgBox ("Erreur n°" & Number & " :" & vbCrLf & Description)
End Sub

Merci si quelqu'un peut me débloquer sur ce coup-la ce serait sympa

2 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
21 sept. 2005 à 13:33
salut,

ajoute un Winsowk1.Close dans l'évènement Close, et dans le Error

Form1.Winsock1.RemoteHost = host
Form1.Winsock1.RemotePort = port
Form1.Winsock1.Connect
peut être remplacé par
Form1.Winsock1.Connect host, port

Winsock1.SendData strsnd
'chaque commande doit finir par le retour chariot...
Winsock1.SendData vbCrLf
peut être remplacé par
Winsock1.SendData strsnd & vbCrLf

jamais de MsgBox dans le DataArrival.

++
PCPT
3
annehuart Messages postés 2 Date d'inscription vendredi 16 septembre 2005 Statut Membre Dernière intervention 21 septembre 2005
21 sept. 2005 à 11:16
ah oui j'avais oublier le msgbox qui change tout c
MsgBox "winsock state :" & Winsock1.State

voilou
merci
nanou
0
Rejoignez-nous