Serveur UDP

Résolu
cs_Sobieski Messages postés 54 Date d'inscription mardi 22 mars 2005 Statut Membre Dernière intervention 13 mars 2007 - 28 avril 2005 à 10:41
cs_Sobieski Messages postés 54 Date d'inscription mardi 22 mars 2005 Statut Membre Dernière intervention 13 mars 2007 - 28 avril 2005 à 12:43
Salut.
Je voudrais printer dans la console ce qui arrive en UDP sur le port 4321. J'ai fait un bout de code mais ca plante comme il faut :/


using System;


using System.Net;


using System.Net.Sockets;


using System.IO;


using System.Text;





namespace Serveur


{



/// <summary>



/// Summary description for Udru.



/// </summary>



public
class Udru


{



public
int port=4321;



public
byte[] buffer;



public Udru()


{



//



// TODO: Add constructor logic here



//


}



public
void start()


{


Socket serverSocket =
new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Udp);


serverSocket.Listen(5);


System.Console.WriteLine("Server Started");


System.Console.WriteLine("Client connected");


serverSocket.Receive(buffer);


System.Console.WriteLine(buffer.ToString());


}


}


}

Any solution ?

2 réponses

cs_Crazyht Messages postés 1522 Date d'inscription mardi 18 décembre 2001 Statut Membre Dernière intervention 21 août 2010 8
28 avril 2005 à 12:27
Tu as oublié de "Bind" le port avant de faire le Listen (...) :=)

Tu trouvera un exemple ici : http://www.c-sharpcorner.com/Network/simpleTcpUdpServerClientPL2.asp

A++

Crazyht
MVP Visual C#.NET

[Admin Codes-Sources]
[Membre Developer-Association]
3
cs_Sobieski Messages postés 54 Date d'inscription mardi 22 mars 2005 Statut Membre Dernière intervention 13 mars 2007
28 avril 2005 à 12:43
Merci bien !
0
Rejoignez-nous