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

Windows Forms Discussion :

Perte de l'affichage


Sujet :

Windows Forms

  1. #1
    Nouveau membre du Club
    Profil pro
    Inscrit en
    Avril 2007
    Messages
    30
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2007
    Messages : 30
    Points : 28
    Points
    28
    Par défaut Perte de l'affichage
    Bonjour tout le monde, je travaille sur application client serveur TCP, je bloque au niveau du serveur, en mode console tout marche bien, mais une fois que j'integre une interface graphique au moment de l'activation de mon serveur je ne peux plus rien faire, ma fenetre devient blanche

    sachant que mon serveur marche bien meme avec la fenetre bloqué j'arrive toujours a envoyé et recevoir les donnée.

    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
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.IO;
    using System.Net;
    using System.Net.Sockets;
    using System.Windows.Forms;
     
    namespace Serveur_Socket_Oracle
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                try
                {
     
                    Int32 port = 9050;
                    IPAddress localAddr;
                    if (!textBox1.Text.Equals(""))
                    {
                        localAddr = IPAddress.Parse(textBox1.Text);
     
                        // TcpListener server = new TcpListener(port);
                        TcpListener server = new TcpListener(localAddr, port);
     
                        // Start listening for client requests.
                        server.Start();
     
                        // Buffer for reading data
                        Byte[] bytes = new Byte[1000];
                        String data = null;
     
                        // Enter the listening loop.
                        while (true)
                        {
                            textBox2.Text = "Waiting for a connection...\n ";
     
                            // Perform a blocking call to accept requests.
                            // You could also user server.AcceptSocket() here.
                            TcpClient client = server.AcceptTcpClient();
                            textBox2.Text = textBox2.Text + "Connected!\n";
     
                            data = null;
     
                            // Get a stream object for reading and writing
                            NetworkStream stream = client.GetStream();
     
                            int i;
     
                            // Loop to receive all the data sent by the client.
                            while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
                            {
                                // Translate data bytes to a ASCII string.
                                data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
                                textBox2.Text = textBox2.Text + String.Format("Received: {0}", data) + "\n";
     
                                // Process the data sent by the client.
                                data = "OK";
     
                                byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
     
                                // Send back a response.
                                stream.Write(msg, 0, msg.Length);
                                textBox2.Text = textBox2.Text + String.Format("Sent: {0}", data) + "\n";
                            }
     
                            // Shutdown and end connection
                            client.Close();
                        }
                    }
                }
                catch (SocketException eee)
                {
                    textBox2.Text = textBox2.Text + "SocketException: {0}";
                }
            }
        }
    }

  2. #2
    Expert confirmé

    Homme Profil pro
    Développeur .NET
    Inscrit en
    Novembre 2010
    Messages
    2 065
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Rhône (Rhône Alpes)

    Informations professionnelles :
    Activité : Développeur .NET

    Informations forums :
    Inscription : Novembre 2010
    Messages : 2 065
    Points : 4 229
    Points
    4 229
    Par défaut
    je pense qu'il doit s’exécuter sur le même thread que ton affichage et doit donc bloqué ton affichage le temps de son éxécution (et comme il s'arrête jamais)
    tu peux utilisé le backgroundworker dans ton cas ou encore les threads (il y a plein de tutos sur developpez.com)
    http://glarde.developpez.com/dotnet/bgworker/cs/

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

Discussions similaires

  1. Réponses: 0
    Dernier message: 17/02/2014, 16h51
  2. Réponses: 1
    Dernier message: 09/01/2012, 21h06
  3. (affichage) perte de données
    Par Albat_r dans le forum 4D
    Réponses: 16
    Dernier message: 05/01/2009, 10h26
  4. Perte d affichage des JPanel
    Par Akatatahoe dans le forum AWT/Swing
    Réponses: 1
    Dernier message: 06/03/2008, 05h20
  5. Perte de session lors du 1er affichage
    Par messier79 dans le forum Langage
    Réponses: 1
    Dernier message: 22/08/2007, 15h26

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