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

Web & réseau Delphi Discussion :

Envoi donnes par socket


Sujet :

Web & réseau Delphi

  1. #1
    Membre habitué Avatar de astrotouf
    Profil pro
    Consultant informatique
    Inscrit en
    Avril 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Avril 2005
    Messages : 221
    Points : 132
    Points
    132
    Par défaut Envoi donnes par socket
    salut a tous.voila j'utilise delphi 7 et j'essaye de faire une application pour mon TP reseau et j'utilise les sockets TServerSocket et TClientSocket pour la connexion de l'application client et serveur.
    mon probleme est que je ne sais pas comment faire pour envoyer des donness autre que de type texte ( integer, boolean...etc).
    la seule fonction que j'ai reussi a utiliser est Socket.SendText.
    voila je vous remercie d'avance pour vos reponses.

  2. #2
    Expert éminent sénior
    Avatar de ShaiLeTroll
    Homme Profil pro
    Développeur C++\Delphi
    Inscrit en
    Juillet 2006
    Messages
    13 573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 43
    Localisation : France, Seine Saint Denis (Île de France)

    Informations professionnelles :
    Activité : Développeur C++\Delphi
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Juillet 2006
    Messages : 13 573
    Points : 25 206
    Points
    25 206
    Par défaut
    Tient voilà du code de mon application à bordel, cela peut te donner des idées


    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
    procedure TFrmShowJPEG.BtnSendClick(Sender: TObject);
    var
       Index: Integer;
       DummyJPEg: TJPEGImage;
       DummyBitmap: TBitmap;
       DummyStream: TMemoryStream;
    begin
       DummyJPEg := TJPEGImage.Create();
       try
          DummyBitmap := TBitmap.Create();
          try
             DummyStream := TMemoryStream.Create();
             try
                DummyBitmap.Assign(ImageWithDate.Picture.Bitmap);
                DummyBitmap.Canvas.TextOut(0, 0, 'Copy');
                // DummyBitmap.SaveToStream(DummyStream);
                DummyJPEg.Assign(DummyBitmap);
                DummyJPEg.SaveToStream(DummyStream);
     
                if DummyStream.Size > 0 then
                begin
                   for Index := 0 to ServerSocketJPEG.Socket.ActiveConnections - 1 do
                   begin
                      if ServerSocketJPEG.Socket.Connections[Index].Connected then
                         ServerSocketJPEG.Socket.Connections[Index].SendBuf(DummyStream.Memory^, DummyStream.Size);
                         begin
                            lblRead.Caption := 'Envoyé ...';
                         end;
                         Application.ProcessMessages();
                   end;
                end else
                begin
                   lblRead.Caption := 'Stream Vide ...';
                end;
     
             finally
                DummyStream.Free(); // Voir l'aide de Delphi pour le TCustomWinSocket.SendStream
             end;
          finally
             DummyBitmap.Free();
          end;
       finally
          DummyJPEg.Free();
       end;
    end;
     
    procedure TFrmShowJPEG.ClientSocketJPEGRead(Sender: TObject;
      Socket: TCustomWinSocket);
    var
       DummyStream: TMemoryStream;
       DummyJPEg: TJPEGImage;
       Count, TotalCount: Integer;
       Buffer: Pointer;
    begin
       ClientSocketJPEG.OnRead := nil;
       try
         lblRead.Caption := 'Réception ...'; lblRead.Refresh();
         try
            DummyStream := TMemoryStream.Create();
            try
               Count := 0;
               TotalCount := 0;
     
               repeat
                 lblRead.Caption := 'Réception ... ' + IntToStr(Socket.ReceiveLength) + ' / ' + IntToStr(TotalCount) + '                 '; lblRead.Refresh();
                 DummyStream.SetSize(TotalCount+Socket.ReceiveLength);
                 Count := Socket.ReceiveBuf(Pointer(Integer(DummyStream.Memory)+TotalCount)^, Socket.ReceiveLength);
                 Inc(TotalCount, Count);
     
                 MemoLog.Lines.Add(lblRead.Caption);
                 Application.ProcessMessages();
               until Count <= 0;
     
               DummyJPEg := TJPEGImage.Create();
               try
                  DummyJPEg.LoadFromStream(DummyStream);
                  ImageRead.Picture.Bitmap.Assign(DummyJPEg);
     
               finally
                  DummyJPEg.Free();
               end;
            finally
               DummyStream.Free();
            end;
     
            lblRead.Caption := 'Terminé !';
         except
            lblRead.Caption := 'Except : ' + Exception(ExceptObject).Message;
         end;
      finally
         ClientSocketJPEG.OnRead := ClientSocketJPEGRead;
      end;
    end;

  3. #3
    Expert confirmé
    Avatar de Sub0
    Homme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2002
    Messages
    3 573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2002
    Messages : 3 573
    Points : 4 219
    Points
    4 219
    Par défaut
    Salut!

    Perso, je me servirait de la démo de Nono40 comme base de mon code. Il permet de transférer un fichier, et donc, n'importe quel type de donnée...

    http://nono40.developpez.com/sources/source0015/

    Tu peux aussi envisager d'utiliser les fichiers typés, les enregistrements, etc, afin de sauver tes objets / tes données dans un stream et réaliser son transfert...

    http://www.developpez.net/forums/sho...=216030&page=2
    http://delphi.developpez.com/faq/?pa...ringdanstsream

  4. #4
    Membre habitué Avatar de astrotouf
    Profil pro
    Consultant informatique
    Inscrit en
    Avril 2005
    Messages
    221
    Détails du profil
    Informations personnelles :
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Consultant informatique

    Informations forums :
    Inscription : Avril 2005
    Messages : 221
    Points : 132
    Points
    132
    Par défaut
    merci a tous.
    vos methodes marchent toutes.

  5. #5
    Expert confirmé
    Avatar de Sub0
    Homme Profil pro
    Développeur Web
    Inscrit en
    Décembre 2002
    Messages
    3 573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 51

    Informations professionnelles :
    Activité : Développeur Web

    Informations forums :
    Inscription : Décembre 2002
    Messages : 3 573
    Points : 4 219
    Points
    4 219
    Par défaut
    le tag (bouton en bas de cette fenêtre)

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

Discussions similaires

  1. Envoi donnée par mail
    Par miikenomore dans le forum Général JavaScript
    Réponses: 5
    Dernier message: 26/06/2012, 08h44
  2. Serveur multithreads, envoie données par socket
    Par Orci76 dans le forum Threads & Processus
    Réponses: 5
    Dernier message: 15/07/2010, 17h44
  3. Envoie image par Socket
    Par hussein47 dans le forum VB.NET
    Réponses: 13
    Dernier message: 27/08/2009, 19h28
  4. Envoie Fichier par socket
    Par Invité dans le forum C#
    Réponses: 3
    Dernier message: 28/02/2008, 08h57
  5. Flux de données par socket
    Par formentor dans le forum Entrée/Sortie
    Réponses: 11
    Dernier message: 29/05/2007, 09h24

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