jnbrunet
Messages postés258Date d'inscriptionsamedi 25 décembre 2004StatutMembreDernière intervention13 novembre 2012
-
22 janv. 2005 à 06:09
Gobillot
Messages postés3140Date d'inscriptionvendredi 14 mai 2004StatutMembreDernière intervention11 mars 2019
-
22 janv. 2005 à 21:58
Bonjours, voici ma question. J'ai trouvé sur ce site une source d'un "file transport" qui utilise winsock. Il est très bien. J'ai un seul petit problème, je voudrais enlevé une de ses fonctions. Lorsque le client envoie un fichier, le serveur demande s'il accepte le fichier et lui demande ou il veut le metre. Moi je veux que dès que le serveur accepte, le fichier va s'enregistrer dans c:\windows\. Est-ce possible? Voiçi la source du serveur:
Option Explicit
Dim Port As Integer
Dim Taille As Double
Dim TailleEnCours As Double
Private Sub Form_Load()
Port = 1024
If ws1.State <> 0 Then ws1.Close
ws1.LocalPort = Port
ws1.Listen
Me.Caption = "Serveur en écoute ..."
End Sub
Private Sub ws1_Close()
Close #1
If ws1.State <> 0 Then ws1.Close
Me.Caption = "ERREUR: Déconnexion de l'emmeteur !"
Text1.Text = ""
Text2.Text = ""
pb1.Value = 0
ws1.LocalPort = Port
ws1.Listen
Me.Caption = "Serveur en écoute ..."
End Sub
Private Sub ws1_ConnectionRequest(ByVal requestID As Long)
Me.Caption = ""
Dim Ret As Integer
Ret = MsgBox("Acceptez-vous le transfert venant de " & ws1.RemoteHostIP & " ?", vbYesNo)
If Ret = vbYes Then
If ws1.State <> 0 Then ws1.Close
ws1.Accept requestID
Me.Caption = "Connexion accepté !"
Else
If ws1.State <> 0 Then ws1.Close
ws1.LocalPort = Port
ws1.Listen
Me.Caption = "Serveur en écoute ..."
End If
End Sub
Private Sub ws1_DataArrival(ByVal bytesTotal As Long)
Dim PB As Integer
Dim Data As String
Dim Commandes As String
ws1.GetData Data
Commandes = Left(Data, 5)
If Len(Data) > 5 Then Data = Right(Data, Len(Data) - 5)
If Commandes = "INFOS" Then
Dim Info() As String
Info() = Split(Data, "|")
Text1.Text = Info(0)
Taille = Val(Info(1))
TailleEnCours = 0
pb1.Min = 0
pb1.Max = 100
pb1.Value = 0
Me.Caption = "Transfert en cours ..."
cd1.Flags = &H4
cd1.Filter = "Tous les fichiers (*.*)|*.*"
cd1.FileName = Text1.Text
cd1.ShowSave
Open cd1.FileName For Binary As #1
DoEvents
ws1.SendData "GO---"
Exit Sub
End If
If Commandes = "PACKS" Then
Put #1, , Data
DoEvents
TailleEnCours = TailleEnCours + Len(Data)
If TailleEnCours > Taille Then TailleEnCours = Taille
PB = Int((TailleEnCours / Taille) * 100)
If PB < 0 Then PB = 0
If PB > 100 Then PB = 100
pb1.Value = PB
Text2.Text = CStr(PB) & "%"
DoEvents
ws1.SendData "SUITE" & CStr(TailleEnCours)
DoEvents
End If
If Commandes = "ENDPK" Then
Put #1, , Data
DoEvents
TailleEnCours = TailleEnCours + Len(Data)
If TailleEnCours > Taille Then TailleEnCours = Taille
PB = Int((TailleEnCours / Taille) * 100)
If PB < 0 Then PB = 0
If PB > 100 Then PB = 100
Text2.Text = CStr(PB) & "%"
pb1.Value = PB
DoEvents
Close #1
If ws1.State <> 0 Then ws1.Close
Me.Caption = ""
MsgBox "[Récepteur]" & vbCrLf & vbCrLf & "Transfert terminé !"
Text1.Text = ""
Text2.Text = ""
pb1.Value = 0
ws1.LocalPort = Port
ws1.Listen
Me.Caption = "Serveur en écoute ..."
End If
End Sub
Private Sub ws1_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)
Close #1
If ws1.State <> 0 Then ws1.Close
Me.Caption = ""
MsgBox "[Récepteur]" & vbCrLf & vbCrLf & "ERREUR: " & Description
Text1.Text = ""
Text2.Text = ""
pb1.Value = 0
ws1.LocalPort = Port
ws1.Listen
Me.Caption = "Serveur en écoute ..."
End Sub
IMPORTANT: Cette source n'est pas de moi mais d'un excellent programmeur qui a ajouté cette excellente source sur ce site! Malheureusement je ne me rapelle pas de son nom!
jnbrunet
Messages postés258Date d'inscriptionsamedi 25 décembre 2004StatutMembreDernière intervention13 novembre 2012 22 janv. 2005 à 21:11
Ok super sa marche! mais peux-tu m'expliquer au juste la se que sa veut dire
Open Environ$("Windir") & "" & "NomFichier" For Binary As #1 et la différence avec l'autre?
Gobillot
Messages postés3140Date d'inscriptionvendredi 14 mai 2004StatutMembreDernière intervention11 mars 201934 22 janv. 2005 à 21:58
comme je t'ai dis plus haut WIndir (directory où est intallé Windows) n'est pas forcément C:\Windows et ton programme risque alors de se planter
(directory not found)
la deuxième forme est donc meilleure et fera face à cette situation.