Skip to content
Snippets Groups Projects
Commit 8af4618a authored by Charles Still's avatar Charles Still
Browse files

Chatmessage v1.1

parent 5a0c159e
No related merge requests found
Showing
with 30 additions and 30 deletions
No preview for this file type
No preview for this file type
......@@ -64,12 +64,17 @@ namespace ClientUdp
byte[] pseudoByte = Encoding.ASCII.GetBytes(this.pseudo);
for (int i = 0; i < pseudoByte.Length; i++) // car 20 char pour un pseudo
res[i+2] = pseudoByte[i];
for (int i = 0; i < 20; i++)
{ // car 20 char pour un pseudo
if (i < pseudoByte.Length)
res[i + 2] = pseudoByte[i];
else
res[i + 2] = 32;
}
for (int i = 0; i < 4; i++) // une taille est codée sur 4 bits
res[i+22] = tailleDataByte[i];
for(int i = 0; i < dataByte.Length; i++) // le message allant de la position 26 à 1499
res[i+26] = dataByte[i ];
res[i+26] = dataByte[i];
}
else
......
......@@ -11,28 +11,7 @@ namespace ClientUdp
{
class ClientUdp
{
/* static Thread ecoute;
static Thread ecrire;
static void enEcoute()//TODO : Thread qui écoute les messages du serveur
{
while (ecoute.IsAlive)
{
}
}
static void envoiMessage()
{
while (ecrire.IsAlive)
{
}
}
static void CreationThread()
{
ecoute = new Thread(new ThreadStart(enEcoute));
}*/
static String[] messagePost =
{
"coucoucocucoucoucoucoucoucocuocu",
......@@ -53,8 +32,19 @@ namespace ClientUdp
//************************************************************** Initialisation
string serverIP = "192.168.43.4"; // A changer
int serverPort = 11115 ; // A changer
int clientPort = 0;
bool portInit=false;
do
{
Console.WriteLine("Votre port?");
String port = Console.ReadLine();
if (int.TryParse(port, out clientPort))
{
portInit = true;
}
} while (!portInit);
// Création de la socket d'écoute UDP
Socket clientSocket = new Socket(
......@@ -64,7 +54,7 @@ namespace ClientUdp
// Liaison de la socket au point de communication
clientSocket.Bind(new IPEndPoint(IPAddress.Any, 22222));
clientSocket.Bind(new IPEndPoint(IPAddress.Any, clientPort));
//ChatMessage msg = new ChatMessage((Commande)1, (CommandeType)1, "Coucou", "Nice");
//définition du port
......@@ -97,7 +87,9 @@ namespace ClientUdp
foreach(String s in messagePost)
{
clientSocket.SendTo(new ChatMessage(Commande.POST, CommandeType.REQUETE, s, "Cédric Wemmert").GetBytes(),serverEP);
clientSocket.ReceiveFrom(buffer, ref serverEP);
}
string req = "y";
......@@ -163,7 +155,8 @@ namespace ClientUdp
+ " (" + cm.dataSize + " octets)"
+ ": \"" + cm.data + "\"");
clientSocket.SendTo(cm.GetBytes(), serverEP);
byte[] buffer = new byte[1500];
clientSocket.ReceiveFrom(buffer, ref serverEP);
}
public static void envoieMsgGet(EndPoint serverEP, Socket clientSocket)
......@@ -172,9 +165,11 @@ namespace ClientUdp
byte[] buffer = new byte[1500];
clientSocket.ReceiveFrom(buffer, ref serverEP);
ChatMessage repget = new ChatMessage(buffer);
Console.WriteLine(buffer.Length);
Console.WriteLine(repget.data.Length);
foreach (String s in repget.data.Split('\0'))
Console.WriteLine(s);
Console.WriteLine(s.Trim('\0'));
}
}
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment