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 :

Mon Client / Serveur UDP plante


Sujet :

Windows Forms

  1. #1
    Membre à l'essai
    Inscrit en
    Décembre 2006
    Messages
    46
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Décembre 2006
    Messages : 46
    Points : 17
    Points
    17
    Par défaut Mon Client / Serveur UDP plante
    Bonsoir,

    J'ai développé une application client / serveur pour envoyer et recevoir des paquet UDP.
    J'ai un problème avec mon thread.

    A la premiere utilisation du serveur, cela fonctionne bien. Mais quand je le relance, il plante lamentablement.

    Pouvez-vous m'aider?

    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
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Net;
    using System.Net.Sockets;
    using System.Threading;
     
    namespace ServeurUDP
    {
        public partial class Form1 : Form
        {
            private int port = 9500; //Port for the Server to use
            private int ip = 127001;//IP Address 127.0.0.1
            private UdpClient server;
            private Thread startServer;
     
            public Form1()
            {
                InitializeComponent();
                server = new UdpClient(port);
            }
     
            private void button1_Click(object sender, EventArgs e)
            {
                startServer = new Thread(new ThreadStart(start_server));
                startServer.Start();
            }
     
            private void button2_Click(object sender, EventArgs e)
            {
                button2.Enabled = false;
                button1.Enabled = true;
                textBox1.Text += "Fin écoute...\r\n";
                startServer.Abort();
                server.Close();
            }
     
            public void start_server()
            {
                textBox1.Text += "Ecoute...\r\n";
                IPEndPoint receivePoint = new IPEndPoint(new IPAddress(ip), port);
     
                button2.Enabled = true;
                button1.Enabled = false;
     
                //Infinite loop
                while (true)
                {
                    //Receive DataGram
                    byte[] recData = server.Receive(ref receivePoint);
                    string returnData = Encoding.ASCII.GetString(recData);
     
                    textBox1.Text += "Paquet reçu ( " + returnData + " )\r\n";
                }
            }
     
        }
    }

  2. #2
    Rédacteur
    Avatar de SaumonAgile
    Homme Profil pro
    Team leader
    Inscrit en
    Avril 2007
    Messages
    4 028
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Moselle (Lorraine)

    Informations professionnelles :
    Activité : Team leader
    Secteur : Conseil

    Informations forums :
    Inscription : Avril 2007
    Messages : 4 028
    Points : 6 334
    Points
    6 334
    Par défaut
    Qu'entends tu par "il plante" ? Quel est le message exact ?
    Besoin d'un MessageBox amélioré ? InformationBox pour .NET 1.1, 2.0, 3.0, 3.5, 4.0 sous license Apache 2.0.

    Bonnes pratiques pour les accès aux données
    Débogage efficace en .NET
    LINQ to Objects : l'envers du décor

    Mon profil LinkedIn - MCT - MCPD WinForms - MCTS Applications Distribuées - MCTS WCF - MCTS WCF 4.0 - MCTS SQL Server 2008, Database Development - Mon blog - Twitter

  3. #3
    Membre à l'essai
    Inscrit en
    Décembre 2006
    Messages
    46
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Décembre 2006
    Messages : 46
    Points : 17
    Points
    17
    Par défaut
    Erreur Windows : voir PJ
    Images attachées Images attachées  

  4. #4
    Membre à l'essai
    Inscrit en
    Décembre 2006
    Messages
    46
    Détails du profil
    Informations personnelles :
    Âge : 40

    Informations forums :
    Inscription : Décembre 2006
    Messages : 46
    Points : 17
    Points
    17
    Par défaut
    Personne n'a une idée?
    Peut-etre un problème avec le thread, non?

Discussions similaires

  1. Programmation Client/Serveur UDP
    Par most27 dans le forum Débuter avec Java
    Réponses: 0
    Dernier message: 29/10/2014, 19h49
  2. Réponses: 2
    Dernier message: 08/11/2012, 16h07
  3. Blocage recvmsg (client/serveur udp)
    Par tenebriox dans le forum Réseau
    Réponses: 1
    Dernier message: 07/11/2012, 21h47
  4. Client serveur UDP en JAVA
    Par caro_caro dans le forum Entrée/Sortie
    Réponses: 4
    Dernier message: 29/09/2008, 23h16
  5. [ServerSocket]Problème communication client-serveur udp sur linux
    Par gdecrouez dans le forum Entrée/Sortie
    Réponses: 2
    Dernier message: 29/09/2006, 15h59

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