IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

VB 6 et antérieur Discussion :

Winsock connexion successive impossible


Sujet :

VB 6 et antérieur

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé Avatar de Ramdoulou
    Profil pro
    Étudiant
    Inscrit en
    Novembre 2006
    Messages
    286
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2006
    Messages : 286
    Par défaut Winsock connexion successive impossible
    Bonjour à tous,

    Donc voilà, j'ai réussi à faire fonctionner le contrôle winsock, envoyer des informations localement et à distance sur plusieurs pc (clients) connectés en même temps.

    Mais j'ai un soucis.

    Si je prend un exemple tout basique :

    j'ai le serveur sur un pc, et le clien sur un autre.
    Je fais une connexion à distance.
    Tout va bien.

    Je déconnecte le client, et me reconnecte avec.
    Si il y a envoi d'information du Serveur au client, j'aurai une erreur du style :
    "Erreur d'execution '40006'
    Etat de connexion ou de protocole erroné pour la transaction ou la requête requise", une erreur concernant le Serveur.
    Evidemment cela me le fait dès la reconnexion du client car le nombre de client total augmente de 1, et le serveur envoi à tous les clients le message "/i\Nouveau client".

    Donc je suppose que la connexion se ferme mal au niveau du serveur pour le client donné, mais j'ai beau toucher à tout, ça ne change rien...=/

    Donc je me tourne vers vous, en vous déposant le code du serveur et du client, afin de voir si vous trouvez la petite erreur.
    Question de patience, alors je vous remercie d'avance du temps que vous consacrerez à mon problème.


    Code Serveur :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    Dim NbClient As Byte
    Dim strData As String
    Dim i As Byte
    Dim nbr As Long
     
     
    Private Sub Command1_Click()
     nbr = NbrEnr.Caption
     For i = 1 To NbClient
        tcpServer(i).SendData Me.txtSendData.Text
    Next i
    txt.Text = txt.Text & vbCrLf & txtSendData.Text
    NbrEnr.Caption = nbr + 1
    End Sub
     
    Private Sub Command2_Click()
        nbr = NbrEnr.Caption
        Dim X As String
        Dim Y As String
     
    X = C1.Text
    Y = C2.Text
     
     For i = 1 To NbClient
        tcpServer(i).SendData "C²|" & X & "|" & Y
    Next i
    txt.Text = txt.Text & vbCrLf & "C²|" & X & "|" & Y
    NbrEnr.Caption = nbr + 1
    End Sub
     
    Private Sub Command3_Click()
    Unload Me
    End Sub
     
    Private Sub Command4_Click()
    tcpServer(0).Listen
    End Sub
     
    Private Sub envoi2_Click()
     
    End Sub
     
    Private Sub Form_Load()
        intMax = 0
    tcpServer(0).LocalPort = 1001
    tcpServer(0).Listen
     
     
          ' Donne à la propriété LocalPort une valeur
          ' entière. Puis invoque la méthode Listen.
    End Sub
     
    Private Sub tcpServer_DataArrival _
    (Index As Integer, ByVal bytesTotal As Long)
    nbr = NbrEnr.Caption
    ' Déclare une variable pour les données reçues.
    ' Invoque la méthode GetData et paramètre pour
    ' ces données la propriété Text d'un contrôle
    ' TextBox nommé txtOutput.
    'tcpServer(intMax).GetData strData
    tcpServer(Index).GetData strData
    txtOutput(Index).Caption = strData
    'txt.Text = txt.Text & vbCrLf & strData
    NbrEnr.Caption = nbr + 1
    Me.txtSendData.Text = strData
    Command1_Click
     
    Dim Ch As String
    Dim CutCh
    Ch = txtOutput(Index).Caption & vbCrLf
     
    CutCh = Split(Ch, "|")
     
    Select Case CutCh(0)
    Case "Text"
        txt.Text = txt.Text & vbCrLf & CutCh(1)
    'On renvoit vers les autres clients
     For i = 1 To NbClient
        tcpServer(i).SendData strData
    Next i
     
    Case "Deco"
        dcxID.Text = dcxID.Text & vbCrLf & "Déconnexion de " & Str(requestID)
     
        Me.tcpServer(0).Close
        'NbClient = NbClient - 1
     
    Case Else
      'MsgBox "Données non identifiables"
    End Select
     
     
    End Sub
     
    Private Sub tcpServer_ConnectionRequest _
    (Index As Integer, ByVal requestID As Long)
     
       If Index = 0 Then
          NbClient = NbClient + 1
          Load tcpServer(NbClient)
          tcpServer(NbClient).LocalPort = 0
          tcpServer(0).Close
          tcpServer(NbClient).Accept requestID
              txtSendData.Text = "/i\Nouveau connecté"
          Command1_Click
          Load txtOutput(NbClient)
       End If
     
    ' Vérifie que le contrôle est fermé. Sinon, ferme
    ' la connexion en cours avant d'accepter la
    ' nouvelle.
    'If tcpServer.State <> sckClosed Then _
    tcpServer.Close
    ' Accepte la demande avec le paramètre requestID.
    'tcpServer.Accept requestID
    End Sub
     
    Private Sub Timer2_Timer()
    stat.Caption = tcpServer(0).State
     
    If stat.Caption = "0" Then
    tcpServer(0).Listen
    End If
    End Sub
     
    Private Sub Timer3_Timer()
    nb.Caption = NbClient
    str2.Caption = i
    End Sub
     
    Private Sub txtSendData_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyRight Then
    Me.Image1.Left = Me.Image1.Left + 100
    C1.Text = Image1.Left
    C2.Text = Image1.Top
    Command2_Click
    End If
     
    If KeyCode = vbKeyLeft Then
    Me.Image1.Left = Me.Image1.Left - 100
    C1.Text = Image1.Left
    C2.Text = Image1.Top
    Command2_Click
    End If
     
    If KeyCode = vbKeyDown Then
    Me.Image1.Top = Me.Image1.Top + 100
    C1.Text = Image1.Left
    C2.Text = Image1.Top
    Command2_Click
    End If
     
    If KeyCode = vbKeyUp Then
    Me.Image1.Top = Me.Image1.Top - 100
    C1.Text = Image1.Left
    C2.Text = Image1.Top
    Command2_Click
    End If
     
     
    End Sub
    Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = vbKeyRight Then
    Me.Image1.Left = Me.Image1.Left + 100
    C1.Text = Image1.Left
    C2.Text = Image1.Top
    Command2_Click
    End If
     
    If KeyCode = vbKeyLeft Then
    Me.Image1.Left = Me.Image1.Left - 100
    C1.Text = Image1.Left
    C2.Text = Image1.Top
    Command2_Click
    End If
     
    If KeyCode = vbKeyDown Then
    Me.Image1.Top = Me.Image1.Top + 100
    C1.Text = Image1.Left
    C2.Text = Image1.Top
    Command2_Click
    End If
     
    If KeyCode = vbKeyUp Then
    Me.Image1.Top = Me.Image1.Top - 100
    C1.Text = Image1.Left
    C2.Text = Image1.Top
    Command2_Click
    End If
    End Sub

    Code Client :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
     
    Private Sub Command1_Click()
    MsgBox tcpClient.State
    End Sub
     
    Private Sub Command2_Click()
    Me.txtSend.Refresh
    Me.txtOutput.Refresh
    End Sub
     
    Private Sub Command3_Click()
    tcpClient.SendData "Client : " & txtSend.Text
    'txt.Text = txt.Text & vbCrLf & "Client : " & txtSend.Text
    End Sub
     
    Private Sub Command4_Click()
    Unload Me
    End Sub
     
    Private Sub Command5_Click()
     
    End Sub
     
    Private Sub Form_Load()
     
    ' Le nom du contrôle Winsock est tcpClient.
    ' Note : pour spécifier un hôte distant, vous pouvez utiliser soit
    ' l'adresse IP (ex: "121.111.1.1"), soit le nom complet de
    ' l'ordinateur, comme ci-dessous.
    'tcpClient.RemoteHost = "192.168.1.86"
    'tcpClient.RemotePort = 1001
    stat.Caption = "Déconnecté"
    End Sub
     
    Private Sub cmdConnect_Click()
    ' Invoque la méthode Connect pour établir une
    ' connexion.
     
    If Option1 = True Then
    'Label1.Caption = "connexion en cours..."
    tcpClient.Connect "192.168.1.86", 1001
    Timer1.Enabled = True
    ElseIf Option2 = True Then
    'Label1.Caption = "connexion en cours..."
    tcpClient.Connect "xxx.xxx.xxx.xxx", 1001  'Ip "externe" masquée ici par sécurité
    Timer1.Enabled = True
    End If
    End Sub
     
    Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
    tcpClient.SendData "Deco|"
    Cancel = 1
    Timer2.Enabled = True
    End Sub
     
    Private Sub tcpClient_DataArrival _
    (ByVal bytesTotal As Long)
    Dim strData As String
    tcpClient.GetData strData
    txtOutput.Caption = strData
    End Sub
     
    Private Sub Timer1_Timer()
    If serverstat.Caption = "7" Then
    Label1.Caption = "connexion réussie"
    stat.Caption = "Connecté"
    Me.Timer3.Enabled = True
    ElseIf serverstat.Caption = "6" Then
    Label1.Caption = "connexion échouée"
    'Me.tcpClient.Close
    End If
    End Sub
     
    Private Sub Timer2_Timer()
    End
    End Sub
     
    Private Sub Timer3_Timer()
    serverstat.Caption = Me.tcpClient.State
     
    If serverstat.Caption = "8" Then
    Me.tcpClient.Close
    stat.Caption = "Déconnecté"
    Label1.Caption = "Perte de connexion"
    End If
     
    If Label1.Caption <> "connexion réussie" Then
     
    led.BackColor = &HC0&
     
    Else
    led.BackColor = &HC000&
     
    End If
    End Sub
     
    Private Sub txtOutput_Change()
    Dim Ch As String
    Dim CutCh
    Dim X As Single
    Dim Y As Single
    Ch = txtOutput.Caption & vbCrLf
     
    CutCh = Split(Ch, "|")
    Select Case CutCh(0)
    Case "C²"
        C1 = CutCh(1)
        C2 = CutCh(2)
        X = C1.Text
        Y = C2.Text
    Debug.Print X, Y
        Me.Image1.Left = X
        Me.Image1.Top = Y
     
    Case "Text"
        txt.Text = txt.Text & vbCrLf & CutCh(1)
    Case "Deco"
        txt.Text = txt.Text & vbCrLf & CutCh(1)
    Case Else
      'MsgBox "Données non identifiables"
    End Select
     
     
    txt.Text = txt.Text & vbCrLf & txtOutput.Caption
     
    End Sub

    Merci

  2. #2
    Membre éclairé Avatar de Ramdoulou
    Profil pro
    Étudiant
    Inscrit en
    Novembre 2006
    Messages
    286
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2006
    Messages : 286
    Par défaut
    Personne n'est en mesure de m'aider ? =o

  3. #3
    Membre Expert Avatar de OhMonBato
    Homme Profil pro
    Inscrit en
    Mars 2007
    Messages
    2 660
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Morbihan (Bretagne)

    Informations professionnelles :
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2007
    Messages : 2 660
    Par défaut
    Dans ta sub de connexion, essaye d'abord de fermer la connexion avant de l'ouvrir :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    Private Sub cmdConnect_Click()
    ' Invoque la méthode Connect pour établir une
    ' connexion.
     
    '************************************
    'A ajouter
    tcpClient.Close
    '************************************
     
    If Option1 = True Then
    'Label1.Caption = "connexion en cours..."
    tcpClient.Connect "192.168.1.86", 1001
    Timer1.Enabled = True
     
    
    Sans garantie bien sûr, mais je n'ai pas d'autre idée.

  4. #4
    Membre éclairé Avatar de Ramdoulou
    Profil pro
    Étudiant
    Inscrit en
    Novembre 2006
    Messages
    286
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2006
    Messages : 286
    Par défaut
    Merci de ta réponse.

    Ca ne fonctionne toujours pas =/

    En effet, je pense plutôt que ça vient du serveur, notamment lorsqu'il est informé de la déconnexion de tel client notamment dans cette partie de code :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    Private Sub tcpServer_DataArrival _
    (Index As Integer, ByVal bytesTotal As Long)
    nbr = NbrEnr.Caption
    ' Déclare une variable pour les données reçues.
    ' Invoque la méthode GetData et paramètre pour
    ' ces données la propriété Text d'un contrôle
    ' TextBox nommé txtOutput.
    'tcpServer(intMax).GetData strData
    tcpServer(Index).GetData strData
    txtOutput(Index).Caption = strData
    'txt.Text = txt.Text & vbCrLf & strData
    NbrEnr.Caption = nbr + 1
    Me.txtSendData.Text = strData
    Command1_Click
     
    Dim Ch As String
    Dim CutCh
    Ch = txtOutput(Index).Caption & vbCrLf
     
    CutCh = Split(Ch, "|")
     
    Select Case CutCh(0)
    Case "Text"
        txt.Text = txt.Text & vbCrLf & CutCh(1)
    'On renvoit vers les autres clients
     For i = 1 To NbClient
        tcpServer(i).SendData strData
    Next i
     
    Case "Deco"
        dcxID.Text = dcxID.Text & vbCrLf & "Déconnexion de " & Str(requestID)
     
        Me.tcpServer(0).Close
        'NbClient = NbClient - 1
     
    Case Else
      'MsgBox "Données non identifiables"
    End Select
     
     
    End Sub
    A la fin dans la case "Deco".
    L'idée serait enfaite à partir du serveur, de fermer automatiquement la connexion entre lui-même et le client dont il vient de recevoir la déconnexion.

  5. #5
    Membre éclairé Avatar de Ramdoulou
    Profil pro
    Étudiant
    Inscrit en
    Novembre 2006
    Messages
    286
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2006
    Messages : 286
    Par défaut
    Ok alors je viens de faire un test.

    J'ai remplacé le code du bouton d'envoi de données, du serveur vers le client, qui était :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Private Sub Command1_Click()
     nbr = NbrEnr.Caption
     For i = 1 To NbClient
        tcpServer(i).SendData Me.txtSendData.Text
    Next i
    txt.Text = txt.Text & vbCrLf & txtSendData.Text
    NbrEnr.Caption = nbr + 1
    End Sub
    par

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    Private Sub Command1_Click()
     nbr = NbrEnr.Caption
     'For i = 1 To NbClient
    '    tcpServer(i).SendData Me.txtSendData.Text
    'Next i
    txt.Text = txt.Text & vbCrLf & txtSendData.Text
    NbrEnr.Caption = nbr + 1
    End Sub

    Alors là, le client peut se connecter de manière successive, et envoyer des données qui sont correctement réceptionnée par le serveur MAIS, aucune donnée ne peut être envoyée du serveur vers le client =x

    Edit:


    En remplaçant
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    tcpServer(i).SendData Me.txtSendData.Text
    par
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    tcpServer(NbClient).SendData Me.txtSendData.Text
    toujours dans le bouton d'envoi de données, le serveur peut envoyer des données, mais seulement vers le dernier client connecté (Nbclient désigne le nombre de client total)...

    Je suis sûr qu'il s'agit d'une simple et bête erreur de variable ='(

    Si vraiment vous ne voyez pas d'où vient le problème, je peux envoyer le projet à celui qui aimerait examiner.
    Je vous remercie d'avance, car pour tout vous dire, je tiens beaucoup à réussir à résoudre ce problème, car il me bloque depuis pas mal de temps =x

  6. #6
    Membre éclairé Avatar de Ramdoulou
    Profil pro
    Étudiant
    Inscrit en
    Novembre 2006
    Messages
    286
    Détails du profil
    Informations personnelles :
    Âge : 33
    Localisation : France

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Novembre 2006
    Messages : 286
    Par défaut
    Voici mon projet à télécharger pour ceux voulant bien se pencher sur mon problème.
    ===> http://rameuh.free.fr/ExperimentationWinsock.zip

    Merci d'avance !!

    ps : désolé pour le bazar xD c'est un projet brouillon : une expérimentation ^^

Discussions similaires

  1. Winsock, connexion impossible à distance
    Par Ramdoulou dans le forum VB 6 et antérieur
    Réponses: 23
    Dernier message: 21/11/2010, 22h34
  2. Connexion ssh impossible
    Par le mage tophinus dans le forum Réseau
    Réponses: 6
    Dernier message: 12/07/2007, 13h37
  3. Connexion entrante impossible pour les serveurs de validation W3C
    Par Squalthor dans le forum Serveurs (Apache, IIS,...)
    Réponses: 30
    Dernier message: 13/10/2006, 17h10
  4. Réponses: 9
    Dernier message: 02/01/2006, 16h05
  5. [C# - Connexion POSTGRESSQL] - Impossible de se connecter
    Par angusyoung34 dans le forum PostgreSQL
    Réponses: 6
    Dernier message: 28/12/2005, 15h16

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo