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

Composants FMX Delphi Discussion :

Envoi de fichier via TetheringApp


Sujet :

Composants FMX Delphi

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 619
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 619
    Billets dans le blog
    65
    Par défaut Envoi de fichier via TetheringApp
    Bonjour et meilleurs vœux, c'est de saison

    Je tente un truc entre une application windows FMX (sur mon PC) et une tablette Android : l'envoi d'une base de données SQLite
    le programme "backoffice" a pour tâche d'envoyer le fichier vers la tablette
    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
    unit MainBackoffice;
     
    interface
     
    uses
      System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
      FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, IPPeerClient,
      IPPeerServer, System.Tether.Manager, System.Tether.AppProfile,
      FMX.Controls.Presentation, FMX.StdCtrls, FireDAC.Stan.Intf,
      FireDAC.Stan.Option, FireDAC.Stan.Error, FireDAC.UI.Intf, FireDAC.Phys.Intf,
      FireDAC.Stan.Def, FireDAC.Stan.Pool, FireDAC.Stan.Async, FireDAC.Phys,
      FireDAC.Phys.SQLite, FireDAC.Phys.SQLiteDef, FireDAC.Stan.ExprFuncs,
      FireDAC.Phys.SQLiteWrapper.Stat, FireDAC.FMXUI.Wait, Data.DB,
      FireDAC.Comp.Client, FMX.Layouts, FMX.ListBox, FMX.Memo.Types, FMX.ScrollBox,
      FMX.Memo;
     
    type
      TForm1 = class(TForm)
        btnSend: TButton;
        TetheringManager1: TTetheringManager;
        TetheringAppProfile1: TTetheringAppProfile;
        btnConnect: TButton;
        FDConnection1: TFDConnection;
        Memo1: TMemo;
        procedure btnSendClick(Sender: TObject);
        procedure btnConnectClick(Sender: TObject);
        procedure TetheringManager1EndManagersDiscovery(const Sender: TObject;
          const ARemoteManagers: TTetheringManagerInfoList);
        procedure TetheringAppProfile1BeforeSendStream(const Sender: TObject;
          const AInputStream, AOutputStream: TStream);
        procedure TetheringAppProfile1AfterReceiveStream(const Sender: TObject;
          const AInputStream, AOutputStream: TStream);
      private
        { Déclarations privées }
      public
        { Déclarations publiques }
      end;
     
    var
      Form1: TForm1;
     
    implementation
     
    {$R *.fmx}
     
    procedure TForm1.btnConnectClick(Sender: TObject);
    begin
    TetheringManager1.DiscoverManagers(2000,'192.168.1.0');
     
    end;
     
    procedure TForm1.btnSendClick(Sender: TObject);
    var
      StreamToSend : TMemoryStream;
     
    const
      DBName = 'D:\serge\Documents\Embarcadero\Studio\Projets\Athenes\FMX\VERON\dbtest1.db';
     
    begin
      StreamToSend := TMemoryStream.Create;
      try
        StreamToSend.LoadFromFile(DBName);
        StreamToSend.Position := 0;
        TetheringAppProfile1.Resources.FindByName('SqliteDB').Value := StreamToSend;
      finally
        // Don't free StreamToSend ?
     
      end;
    end;
     
    procedure TForm1.TetheringAppProfile1AfterReceiveStream(const Sender: TObject;
      const AInputStream, AOutputStream: TStream);
    begin
    Memo1.Lines.Add('received '+AOutputStream.Size.ToString+' octets');
    end;
     
    procedure TForm1.TetheringAppProfile1BeforeSendStream(const Sender: TObject;
      const AInputStream, AOutputStream: TStream);
    begin
    Memo1.Lines.Add('Sending '+AInputStream.Size.ToString+' octets');
    end;
     
    procedure TForm1.TetheringManager1EndManagersDiscovery(const Sender: TObject;
      const ARemoteManagers: TTetheringManagerInfoList);
    var i : integer;
    begin
    memo1.lines.add(ARemoteManagers.count.ToString);
    for i:=0 to ARemoteManagers.count-1 do
     begin
       Memo1.Lines.Add(ARemoteManagers[i].ManagerAdapters);
     end;
    end;
     
    end.
    Seulement, il y a un hic (évidemment sinon je ne posterai pas mon désarroi), si du côté Android ma découverte se fait sans souci,
    côté windows j'ai une erreur (que ce soit avec TetheringManager1.DiscoverManagers(2000,'192.168.1.0'); ou TetheringManager1.AutoConnect(2000,'192.168.1.0');).

    Project backoffice.exe raised exception class EIdSocketError with message 'Erreur de socket n° 10051
    Le réseau est inaccessible.'.
    impliquant que je puisse faire d'envoi

  2. #2
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 619
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 619
    Billets dans le blog
    65
    Par défaut
    Bon, bien évidemment, après consultation des exemples fournis par Embarcadero (bien cachés dans C:\Users\Public\Documents\Embarcadero\Studio\<version>\Samples\Object Pascal\RTL\Tethering)
    Je commence à comprendre mon erreur (en tout cas, plus d'Erreur de socket n° 10051)

    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
     
    procedure TForm1.btnConnectClick(Sender: TObject);
    begin
    TetheringManager1.DiscoverManagers;
    end;
     
     
    procedure TForm1.TetheringManager1EndManagersDiscovery(const Sender: TObject;
      const ARemoteManagers: TTetheringManagerInfoList);
    var i : integer;
    begin
      for I := 0 to ARemoteManagers.Count - 1 do
        if Sametext(ARemoteManagers[I].ManagerText,'mesclients') then
          TetheringManager1.PairManager(aRemoteManagers[I]);
    end;
     
    procedure TForm1.TetheringManager1EndProfilesDiscovery(const Sender: TObject;
      const ARemoteProfiles: TTetheringProfileInfoList);
    var
      I: Integer;
    begin
      memo1.Lines.Clear;
      for I := 0 to ARemoteProfiles.Count - 1 do
        if Sametext(ARemoteprofiles[I].ProfileText,'TetheringAppProfile1') then   // nom sur les clients
          Memo1.Lines.Add(ARemoteProfiles[I].ProfileText);
      if ARemoteProfiles.Count> 0 then
      begin
        TetheringAppProfile1.Connect(ARemoteProfiles[0]);
      end;
      // connexion au permier
    end;
    J'imagine que si j'ai plusieurs clients, je vais devoir faire une boucle d'envoi (pour l'instant je n'en ai qu'un)
    Prochaine étape la récupération du fichier, je croise les doigts

  3. #3
    Rédacteur/Modérateur

    Avatar de SergioMaster
    Homme Profil pro
    Développeur informatique retraité
    Inscrit en
    Janvier 2007
    Messages
    15 619
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 69
    Localisation : France, Loire Atlantique (Pays de la Loire)

    Informations professionnelles :
    Activité : Développeur informatique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Janvier 2007
    Messages : 15 619
    Billets dans le blog
    65
    Par défaut
    Résolu "tard" hier (par tard, j'entends après 17:00 ) voici où j'en suis

    côté Backoffice

    1 - j'ai apparié la liaison

    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
     
    procedure TForm1.btnConnectClick(Sender: TObject);
    begin
    {todo : paramètrage bluetooth ou TCPIP}
    TetheringManager1.DiscoverManagers;   {todo : voir avec AutoConnect}
    end;
     
    procedure TForm1.TetheringManager1EndManagersDiscovery(const Sender: TObject;
      const ARemoteManagers: TTetheringManagerInfoList);
    var i : integer;
    begin
      for I := 0 to ARemoteManagers.Count - 1 do
        if Sametext(ARemoteManagers[I].ManagerText,'Hexatronic') then
          TetheringManager1.PairManager(aRemoteManagers[I]);
    end;
     
    procedure TForm1.TetheringManager1EndProfilesDiscovery(const Sender: TObject;
      const ARemoteProfiles: TTetheringProfileInfoList);
    var
      I: Integer;
    begin
      memo1.Lines.Clear;
      for I := 0 to ARemoteProfiles.Count - 1 do
        if Sametext(ARemoteprofiles[I].ProfileText,'FrontOffice') then
          Memo1.Lines.Add(ARemoteProfiles[I].ProfileText);
      {partie à revoir si plus d'un "client"}
      if ARemoteProfiles.Count> 0 then
      begin
        TetheringAppProfile1.Connect(ARemoteProfiles[0]);  // Connexion au premier
      end;
    end;
    2 - Envoi
    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
    procedure TForm1.btnSendClick(Sender: TObject);
    var
      StreamToSend : TMemoryStream;
     
    const
      DBName = 'dbtest1.db';
     
    begin
      StreamToSend := TMemoryStream.Create;
      try
        StreamToSend.LoadFromFile(DBName);
        StreamToSend.Position := 0;
        TetheringAppProfile1.SendStream(TetheringManager1.RemoteProfiles[0], 'SqliteDB', StreamtoSend);
      finally
        // Libérer ou pas StreamToSend ?
       end;
    end;
    côté Front Office (client), je n'indique pas ici la partie gestion des permissions nécessaires pour Android,

    1 - Connexion au front office
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    procedure TForm1.FormCreate(Sender: TObject);
    begin
    TetheringManager1.AutoConnect(2000,'192.168.1.0');
    {$IFDEF ANDROID}
     PermissionsService.RequestPermissions([PermissionReadExternalStorage, PermissionWriteExternalStorage], AccessPermissionRequestResult, DisplayRationale);
    {$ENDIF}
    end;
    2 - réception
    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
    procedure TForm1.TetheringAppProfile1AfterReceiveStream(const Sender: TObject;
      const AInputStream, AOutputStream: TStream);
    var  FileStream : TFileStream;
    begin
      if FDConnection1.Connected then
         FDConnection1.Connected := False;
      FileName := fdConnection1.Params.Database;
      FileStream := TFileStream.Create(FileName, fmCreate);
      try
          AInputStream.Position := 0;
          FileStream.CopyFrom(AInputStream, AInputStream.Size);
      finally
        FileStream.Free;
        OpenTable;
      end;
    end;
    Le must serait de pouvoir le faire dans les deux sens (Envoi/Réception) mais ça, c'est une autre histoire.
    Je vais continuer avec tethering, avec des communications plus "classiques" de données, mais je considère mon sujet comme clos.

    P.S. l'erreur de socket était en fait certainement due à autre chose (peut-être une exécution du même programme 2 fois sur le même poste).

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. probleme envoie de fichier via pscp
    Par passion_info dans le forum Réseau
    Réponses: 0
    Dernier message: 07/05/2008, 12h58
  2. envoie de fichier via le port série
    Par souma29 dans le forum VB 6 et antérieur
    Réponses: 29
    Dernier message: 17/04/2007, 19h35
  3. Envoi de fichiers via sendmail windows
    Par domiq44 dans le forum Shell et commandes GNU
    Réponses: 2
    Dernier message: 13/12/2006, 09h40
  4. [SSH2] envoi de fichier via scp
    Par samjung dans le forum Bibliothèques et frameworks
    Réponses: 1
    Dernier message: 27/12/2005, 12h09
  5. envoie de fichiers via les formulaires
    Par fabogranqi dans le forum Balisage (X)HTML et validation W3C
    Réponses: 6
    Dernier message: 10/10/2004, 21h34

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