Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Open sidebar
IUT
s32_TRON
Commits
6a939fae
Commit
6a939fae
authored
6 years ago
by
teyermann
Browse files
Options
Download
Plain Diff
conflits
parents
028faecf
ad9e37e7
Changes
86
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
690 additions
and
666 deletions
+690
-666
.gitignore
.gitignore
+3
-0
.gitignore.swp
.gitignore.swp
+0
-0
Chat/ChatMessage.cs
Chat/ChatMessage.cs
+99
-99
Chat/clientUdp/clientUdp.sln
Chat/clientUdp/clientUdp.sln
+25
-25
Chat/clientUdp/clientUdp/ClientUdp.cs
Chat/clientUdp/clientUdp/ClientUdp.cs
+180
-180
Chat/clientUdp/clientUdp/Properties/AssemblyInfo.cs
Chat/clientUdp/clientUdp/Properties/AssemblyInfo.cs
+36
-36
Chat/clientUdp/clientUdp/bin/Debug/clientUdp.exe
Chat/clientUdp/clientUdp/bin/Debug/clientUdp.exe
+0
-0
Chat/clientUdp/clientUdp/bin/Debug/clientUdp.pdb
Chat/clientUdp/clientUdp/bin/Debug/clientUdp.pdb
+0
-0
Chat/clientUdp/clientUdp/clientUdp.csproj
Chat/clientUdp/clientUdp/clientUdp.csproj
+96
-96
Chat/clientUdp/clientUdp/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
.../x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
+0
-0
Chat/clientUdp/clientUdp/obj/x86/Debug/clientUdp.csproj.CoreCompileInputs.cache
...dp/obj/x86/Debug/clientUdp.csproj.CoreCompileInputs.cache
+0
-1
Chat/clientUdp/clientUdp/obj/x86/Debug/clientUdp.csprojAssemblyReference.cache
...Udp/obj/x86/Debug/clientUdp.csprojAssemblyReference.cache
+0
-0
Chat/clientUdp/clientUdp/obj/x86/Debug/clientUdp.exe
Chat/clientUdp/clientUdp/obj/x86/Debug/clientUdp.exe
+0
-0
Chat/clientUdp/clientUdp/obj/x86/Debug/clientUdp.pdb
Chat/clientUdp/clientUdp/obj/x86/Debug/clientUdp.pdb
+0
-0
Chat/clientUdp/clientUdp/obj/x86/Release/clientUdp.csproj.CoreCompileInputs.cache
.../obj/x86/Release/clientUdp.csproj.CoreCompileInputs.cache
+0
-1
Chat/serveurUdp/serveurUdp.sln
Chat/serveurUdp/serveurUdp.sln
+25
-25
Chat/serveurUdp/serveurUdp/Properties/AssemblyInfo.cs
Chat/serveurUdp/serveurUdp/Properties/AssemblyInfo.cs
+36
-36
Chat/serveurUdp/serveurUdp/ServeurUdp.cs
Chat/serveurUdp/serveurUdp/ServeurUdp.cs
+190
-167
Chat/serveurUdp/serveurUdp/bin/Debug/serveurUdp.exe
Chat/serveurUdp/serveurUdp/bin/Debug/serveurUdp.exe
+0
-0
Chat/serveurUdp/serveurUdp/bin/Debug/serveurUdp.pdb
Chat/serveurUdp/serveurUdp/bin/Debug/serveurUdp.pdb
+0
-0
No files found.
.gitignore
View file @
6a939fae
*.vs*
*.exe
*.pdb
*.cache
This diff is collapsed.
Click to expand it.
exemples/UDP/clientUdp/clientUdp/bin/Debug/clientUdp.pdb
→
.gitignore.swp
View file @
6a939fae
No preview for this file type
This diff is collapsed.
Click to expand it.
Chat/ChatMessage.cs
View file @
6a939fae
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
namespace
ClientUdp
{
public
enum
Commande
{
POST
,
GET
,
HELP
,
QUIT
,
STOPSERVEUR
,
SUBSCRIBE
,
SUBSCRIBEv2
,
UNSUBSCRIBE
};
public
enum
CommandeType
{
REQUETE
,
REPONSE
};
class
ChatMessage
{
public
const
int
bufferSize
=
1500
;
public
const
int
pseudoSize
=
30
;
public
const
int
dataSizeMax
=
bufferSize
-
(
pseudoSize
+
2
);
public
Commande
commande
;
// commande
public
CommandeType
commandeType
;
// type (Requête/Réponse)
public
int
dataSize
;
// taille de la donnée
public
String
pseudo
;
// pseudo
public
String
data
;
// données de la commande
public
ChatMessage
(
Commande
commande
,
CommandeType
type
,
String
pseudo
,
String
data
)
{
this
.
commande
=
commande
;
this
.
commandeType
=
type
;
if
(
data
.
Length
<
dataSizeMax
)
{
this
.
data
=
data
;
this
.
dataSize
=
data
.
Length
;
}
else
throw
new
ArgumentOutOfRangeException
(
"Le message est trop long"
);
if
(
pseudo
.
Length
<
pseudoSize
)
this
.
pseudo
=
pseudo
;
else
throw
new
ArgumentOutOfRangeException
(
"Le pseudo est trop long"
);
}
public
ChatMessage
(
byte
[]
buffer
)
{
int
i
=
2
;
if
(
buffer
.
Length
>
bufferSize
)
throw
new
ArgumentException
(
"Buffer du message trop grand"
);
this
.
commande
=
(
Commande
)
buffer
[
0
];
this
.
commandeType
=
(
CommandeType
)
buffer
[
1
];
while
(
i
<
pseudoSize
+
2
&&
buffer
[
i
]
!=
0
)
{
this
.
pseudo
+=
Encoding
.
ASCII
.
GetString
(
buffer
,
i
,
1
);
i
++;
}
i
=
pseudoSize
+
2
;
while
(
i
<
bufferSize
&&
buffer
[
i
]
!=
0
)
{
this
.
data
+=
Encoding
.
ASCII
.
GetString
(
buffer
,
i
,
1
);
i
++;
}
this
.
dataSize
=
this
.
data
.
Length
;
}
public
byte
[]
GetBytes
()
{
byte
[]
res
=
new
byte
[
bufferSize
];
res
[
0
]
=
(
byte
)
this
.
commande
;
res
[
1
]
=
(
byte
)
this
.
commandeType
;
//encodage du pseudo et ajout au tableau de bytes
Encoding
.
ASCII
.
GetBytes
(
this
.
pseudo
,
0
,
this
.
pseudo
.
Length
,
res
,
2
);
//encodage du message et ajout au tableau de bytes
Encoding
.
ASCII
.
GetBytes
(
this
.
data
,
0
,
this
.
data
.
Length
,
res
,
pseudoSize
+
2
);
return
res
;
}
public
static
byte
[]
GetBytes
(
Commande
commande
,
CommandeType
type
,
String
pseudo
,
String
data
)
{
return
new
ChatMessage
(
commande
,
type
,
pseudo
,
data
).
GetBytes
();
}
public
override
string
ToString
()
{
return
"["
+
commande
+
","
+
commandeType
+
",\""
+
pseudo
+
"\","
+
dataSize
+
",\""
+
data
+
"\"]"
;
}
}
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
namespace
ClientUdp
{
public
enum
Commande
{
POST
,
GET
,
HELP
,
QUIT
,
STOPSERVEUR
,
SUBSCRIBE
,
SUBSCRIBEv2
,
UNSUBSCRIBE
};
public
enum
CommandeType
{
REQUETE
,
REPONSE
};
class
ChatMessage
{
public
const
int
bufferSize
=
1500
;
public
const
int
pseudoSize
=
30
;
public
const
int
dataSizeMax
=
bufferSize
-
(
pseudoSize
+
2
);
public
Commande
commande
;
// commande
public
CommandeType
commandeType
;
// type (Requête/Réponse)
public
int
dataSize
;
// taille de la donnée
public
String
pseudo
;
// pseudo
public
String
data
;
// données de la commande
public
ChatMessage
(
Commande
commande
,
CommandeType
type
,
String
pseudo
,
String
data
)
{
this
.
commande
=
commande
;
this
.
commandeType
=
type
;
if
(
data
.
Length
<
dataSizeMax
)
{
this
.
data
=
data
;
this
.
dataSize
=
data
.
Length
;
}
else
throw
new
ArgumentOutOfRangeException
(
"Le message est trop long"
);
if
(
pseudo
.
Length
<
pseudoSize
)
this
.
pseudo
=
pseudo
;
else
throw
new
ArgumentOutOfRangeException
(
"Le pseudo est trop long"
);
}
public
ChatMessage
(
byte
[]
buffer
)
{
int
i
=
2
;
if
(
buffer
.
Length
>
bufferSize
)
throw
new
ArgumentException
(
"Buffer du message trop grand"
);
this
.
commande
=
(
Commande
)
buffer
[
0
];
this
.
commandeType
=
(
CommandeType
)
buffer
[
1
];
while
(
i
<
pseudoSize
+
2
&&
buffer
[
i
]
!=
0
)
{
this
.
pseudo
+=
Encoding
.
ASCII
.
GetString
(
buffer
,
i
,
1
);
i
++;
}
i
=
pseudoSize
+
2
;
while
(
i
<
bufferSize
&&
buffer
[
i
]
!=
0
)
{
this
.
data
+=
Encoding
.
ASCII
.
GetString
(
buffer
,
i
,
1
);
i
++;
}
this
.
dataSize
=
this
.
data
.
Length
;
}
public
byte
[]
GetBytes
()
{
byte
[]
res
=
new
byte
[
bufferSize
];
res
[
0
]
=
(
byte
)
this
.
commande
;
res
[
1
]
=
(
byte
)
this
.
commandeType
;
//encodage du pseudo et ajout au tableau de bytes
Encoding
.
ASCII
.
GetBytes
(
this
.
pseudo
,
0
,
this
.
pseudo
.
Length
,
res
,
2
);
//encodage du message et ajout au tableau de bytes
Encoding
.
ASCII
.
GetBytes
(
this
.
data
,
0
,
this
.
data
.
Length
,
res
,
pseudoSize
+
2
);
return
res
;
}
public
static
byte
[]
GetBytes
(
Commande
commande
,
CommandeType
type
,
String
pseudo
,
String
data
)
{
return
new
ChatMessage
(
commande
,
type
,
pseudo
,
data
).
GetBytes
();
}
public
override
string
ToString
()
{
return
"["
+
commande
+
","
+
commandeType
+
",\""
+
pseudo
+
"\","
+
dataSize
+
",\""
+
data
+
"\"]"
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp.sln
View file @
6a939fae
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2018
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "clientUdp", "clientUdp\clientUdp.csproj", "{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}.Debug|x86.ActiveCfg = Debug|x86
{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}.Debug|x86.Build.0 = Debug|x86
{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}.Release|x86.ActiveCfg = Release|x86
{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CEA829F0-3EBB-4274-B544-54538DA17321}
EndGlobalSection
EndGlobal
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2018
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "clientUdp", "clientUdp\clientUdp.csproj", "{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}.Debug|x86.ActiveCfg = Debug|x86
{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}.Debug|x86.Build.0 = Debug|x86
{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}.Release|x86.ActiveCfg = Release|x86
{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {CEA829F0-3EBB-4274-B544-54538DA17321}
EndGlobalSection
EndGlobal
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp/ClientUdp.cs
View file @
6a939fae
using
System
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.IO
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
namespace
ClientUdp
{
class
ClientUdp
{
private
static
Socket
clientSocket
;
private
static
EndPoint
serverEP
;
public
enum
ClientStatus
{
ENVOI
,
RECEPTION
,
STOP
};
private
static
ClientStatus
status
=
ClientStatus
.
ENVOI
;
public
static
void
Main
(
string
[]
args
)
{
//variable de test des dépassements de mémoire.
String
bufferOverflow
=
new
string
(
'f'
,
10000
);
//Liste des test d'envoi de messages à faire
//List<KeyValuePair<string, object[]>> listeTests = new List<KeyValuePair<string, object[]>>();
Dictionary
<
string
,
object
[
]>
listeTests
=
new
Dictionary
<
string
,
object
[
]>
();
listeTests
.
Add
(
"dataOverflow"
,
new
object
[]
{
Commande
.
POST
,
CommandeType
.
REQUETE
,
"Tim"
,
bufferOverflow
});
listeTests
.
Add
(
"pseudoOverflow"
,
new
object
[]
{
Commande
.
POST
,
CommandeType
.
REQUETE
,
bufferOverflow
,
"test overflow 2"
});
listeTests
.
Add
(
"testPost"
,
new
object
[]
{
Commande
.
POST
,
CommandeType
.
REQUETE
,
"Tim"
,
"test post"
});
listeTests
.
Add
(
"testSubscribe"
,
new
object
[]
{
Commande
.
SUBSCRIBE
,
CommandeType
.
REQUETE
,
"Tim"
,
"test subscribe"
});
listeTests
.
Add
(
"testPost2"
,
new
object
[]
{
Commande
.
POST
,
CommandeType
.
REQUETE
,
"Tim"
,
"test post2"
});
listeTests
.
Add
(
"testGet"
,
new
object
[]
{
Commande
.
GET
,
CommandeType
.
REQUETE
,
"Tim"
,
"test get"
});
Thread
reception
=
new
Thread
(
new
ThreadStart
(
ReceptionMessage
));
try
{
//************************************************************** Initialisation
string
serverIP
=
"127.0.0.1"
;
// A changer
int
serverPort
=
11111
;
// A changer
// Création de la socket d'écoute UDP
clientSocket
=
new
Socket
(
//domaine (IPv4)
AddressFamily
.
InterNetwork
,
//type de socket (Dgram = pas de connexions préalable)
SocketType
.
Dgram
,
ProtocolType
.
Udp
);
// Liaison de la socket au point de communication
clientSocket
.
Bind
(
new
IPEndPoint
(
IPAddress
.
Any
,
0
));
// Création du EndPoint serveur
serverEP
=
new
IPEndPoint
(
IPAddress
.
Parse
(
serverIP
),
serverPort
);
reception
.
Start
();
//envoi des messages
foreach
(
var
element
in
listeTests
)
{
if
(
status
!=
ClientStatus
.
STOP
)
{
object
[]
cmdParam
=
element
.
Value
;
try
{
ChatMessage
chatM
=
new
ChatMessage
((
Commande
)
cmdParam
[
0
],
(
CommandeType
)
cmdParam
[
1
],
(
string
)
cmdParam
[
2
],
(
string
)
cmdParam
[
3
]);
// Encodage du string dans un buffer de bytes en ASCII
byte
[]
buffer
=
chatM
.
GetBytes
();
// Envoie du message au serveur
int
nBytes
=
clientSocket
.
SendTo
(
buffer
,
0
,
buffer
.
Length
,
SocketFlags
.
None
,
serverEP
);
PrintEnvoiMessage
(
chatM
,
element
.
Key
,
nBytes
);
}
catch
(
ArgumentOutOfRangeException
ex
)
{
Console
.
WriteLine
(
""
);
Console
.
WriteLine
(
"Erreur: "
+
ex
.
Message
);
}
}
else
{
break
;
}
}
Console
.
WriteLine
(
"Appuyez sur une touche pour quitter..."
);
Console
.
ReadKey
();
}
catch
(
SocketException
E
)
{
Console
.
WriteLine
(
E
.
Message
);
}
finally
{
//En cas d'erreur ou à la fin, on ferme la socket et on arrete le thread de reception
reception
.
Abort
();
Console
.
WriteLine
(
""
);
Console
.
WriteLine
(
"Fermeture Socket"
);
clientSocket
.
Close
();
}
Console
.
ReadKey
();
}
public
static
void
ReceptionMessage
()
{
byte
[]
buffer
=
new
byte
[
ChatMessage
.
bufferSize
];
while
(
status
!=
ClientStatus
.
STOP
)
{
try
{
//On récupère le packet et on traite le message
int
nBytes
=
clientSocket
.
ReceiveFrom
(
buffer
,
ChatMessage
.
bufferSize
,
SocketFlags
.
None
,
ref
serverEP
);
ChatMessage
msg
=
new
ChatMessage
(
buffer
);
switch
(
msg
.
commande
)
{
case
Commande
.
POST
:
break
;
case
Commande
.
GET
:
PrintReceptionMessage
(
msg
,
nBytes
);
break
;
case
Commande
.
HELP
:
break
;
case
Commande
.
QUIT
:
break
;
case
Commande
.
STOPSERVEUR
:
PrintReceptionMessage
(
msg
,
nBytes
);
status
=
ClientStatus
.
STOP
;
break
;
case
Commande
.
SUBSCRIBE
:
PrintReceptionMessage
(
msg
,
nBytes
);
break
;
case
Commande
.
SUBSCRIBEv2
:
break
;
case
Commande
.
UNSUBSCRIBE
:
break
;
}
}
catch
(
SocketException
E
)
{
Console
.
WriteLine
(
E
.
Message
);
status
=
ClientStatus
.
STOP
;
}
}
}
public
static
void
PrintEnvoiMessage
(
ChatMessage
c
,
string
nomMessage
,
int
nBytes
)
{
PrintMessage
(
c
,
"("
+
nomMessage
+
") "
,
"envoye vers "
,
nBytes
);
}
public
static
void
PrintReceptionMessage
(
ChatMessage
c
,
int
nBytes
)
{
PrintMessage
(
c
,
"reçu de "
,
nBytes
);
}
public
static
void
PrintMessage
(
ChatMessage
c
,
string
action
,
int
nBytes
)
{
PrintMessage
(
c
,
""
,
action
,
nBytes
);
}
public
static
void
PrintMessage
(
ChatMessage
c
,
string
nomMessage
,
string
action
,
int
nBytes
)
{
Console
.
WriteLine
(
""
);
Console
.
Write
(
"Nouveau message "
+
nomMessage
);
Console
.
ForegroundColor
=
ConsoleColor
.
Green
;
Console
.
Write
(
action
);
Console
.
ForegroundColor
=
ConsoleColor
.
White
;
Console
.
WriteLine
(
serverEP
+
" ("
+
nBytes
+
" octets)"
+
": \""
+
c
+
"\""
);
}
}
}
using
System
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.IO
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
namespace
ClientUdp
{
class
ClientUdp
{
private
static
Socket
clientSocket
;
private
static
EndPoint
serverEP
;
public
enum
ClientStatus
{
ENVOI
,
RECEPTION
,
STOP
};
private
static
ClientStatus
status
=
ClientStatus
.
ENVOI
;
public
static
void
Main
(
string
[]
args
)
{
//variable de test des dépassements de mémoire.
String
bufferOverflow
=
new
string
(
'f'
,
10000
);
//Liste des test d'envoi de messages à faire
//List<KeyValuePair<string, object[]>> listeTests = new List<KeyValuePair<string, object[]>>();
Dictionary
<
string
,
object
[
]>
listeTests
=
new
Dictionary
<
string
,
object
[
]>
();
listeTests
.
Add
(
"dataOverflow"
,
new
object
[]
{
Commande
.
POST
,
CommandeType
.
REQUETE
,
"Tim"
,
bufferOverflow
});
listeTests
.
Add
(
"pseudoOverflow"
,
new
object
[]
{
Commande
.
POST
,
CommandeType
.
REQUETE
,
bufferOverflow
,
"test overflow 2"
});
listeTests
.
Add
(
"testPost"
,
new
object
[]
{
Commande
.
POST
,
CommandeType
.
REQUETE
,
"Tim"
,
"test post"
});
listeTests
.
Add
(
"testSubscribe"
,
new
object
[]
{
Commande
.
SUBSCRIBE
,
CommandeType
.
REQUETE
,
"Tim"
,
"test subscribe"
});
listeTests
.
Add
(
"testPost2"
,
new
object
[]
{
Commande
.
POST
,
CommandeType
.
REQUETE
,
"Tim"
,
"test post2"
});
listeTests
.
Add
(
"testGet"
,
new
object
[]
{
Commande
.
GET
,
CommandeType
.
REQUETE
,
"Tim"
,
"test get"
});
Thread
reception
=
new
Thread
(
new
ThreadStart
(
ReceptionMessage
));
try
{
//************************************************************** Initialisation
string
serverIP
=
"127.0.0.1"
;
// A changer
int
serverPort
=
11111
;
// A changer
// Création de la socket d'écoute UDP
clientSocket
=
new
Socket
(
//domaine (IPv4)
AddressFamily
.
InterNetwork
,
//type de socket (Dgram = pas de connexions préalable)
SocketType
.
Dgram
,
ProtocolType
.
Udp
);
// Liaison de la socket au point de communication
clientSocket
.
Bind
(
new
IPEndPoint
(
IPAddress
.
Any
,
0
));
// Création du EndPoint serveur
serverEP
=
new
IPEndPoint
(
IPAddress
.
Parse
(
serverIP
),
serverPort
);
reception
.
Start
();
//envoi des messages
foreach
(
var
element
in
listeTests
)
{
if
(
status
!=
ClientStatus
.
STOP
)
{
object
[]
cmdParam
=
element
.
Value
;
try
{
ChatMessage
chatM
=
new
ChatMessage
((
Commande
)
cmdParam
[
0
],
(
CommandeType
)
cmdParam
[
1
],
(
string
)
cmdParam
[
2
],
(
string
)
cmdParam
[
3
]);
// Encodage du string dans un buffer de bytes en ASCII
byte
[]
buffer
=
chatM
.
GetBytes
();
// Envoie du message au serveur
int
nBytes
=
clientSocket
.
SendTo
(
buffer
,
0
,
buffer
.
Length
,
SocketFlags
.
None
,
serverEP
);
PrintEnvoiMessage
(
chatM
,
element
.
Key
,
nBytes
);
}
catch
(
ArgumentOutOfRangeException
ex
)
{
Console
.
WriteLine
(
""
);
Console
.
WriteLine
(
"Erreur: "
+
ex
.
Message
);
}
}
else
{
break
;
}
}
Console
.
WriteLine
(
"Appuyez sur une touche pour quitter..."
);
Console
.
ReadKey
();
}
catch
(
SocketException
E
)
{
Console
.
WriteLine
(
E
.
Message
);
}
finally
{
//En cas d'erreur ou à la fin, on ferme la socket et on arrete le thread de reception
reception
.
Abort
();
Console
.
WriteLine
(
""
);
Console
.
WriteLine
(
"Fermeture Socket"
);
clientSocket
.
Close
();
}
Console
.
ReadKey
();
}
public
static
void
ReceptionMessage
()
{
byte
[]
buffer
=
new
byte
[
ChatMessage
.
bufferSize
];
while
(
status
!=
ClientStatus
.
STOP
)
{
try
{
//On récupère le packet et on traite le message
int
nBytes
=
clientSocket
.
ReceiveFrom
(
buffer
,
ChatMessage
.
bufferSize
,
SocketFlags
.
None
,
ref
serverEP
);
ChatMessage
msg
=
new
ChatMessage
(
buffer
);
switch
(
msg
.
commande
)
{
case
Commande
.
POST
:
break
;
case
Commande
.
GET
:
PrintReceptionMessage
(
msg
,
nBytes
);
break
;
case
Commande
.
HELP
:
break
;
case
Commande
.
QUIT
:
break
;
case
Commande
.
STOPSERVEUR
:
PrintReceptionMessage
(
msg
,
nBytes
);
status
=
ClientStatus
.
STOP
;
break
;
case
Commande
.
SUBSCRIBE
:
PrintReceptionMessage
(
msg
,
nBytes
);
break
;
case
Commande
.
SUBSCRIBEv2
:
break
;
case
Commande
.
UNSUBSCRIBE
:
break
;
}
}
catch
(
SocketException
E
)
{
Console
.
WriteLine
(
E
.
Message
);
status
=
ClientStatus
.
STOP
;
}
}
}
public
static
void
PrintEnvoiMessage
(
ChatMessage
c
,
string
nomMessage
,
int
nBytes
)
{
PrintMessage
(
c
,
"("
+
nomMessage
+
") "
,
"envoye vers "
,
nBytes
);
}
public
static
void
PrintReceptionMessage
(
ChatMessage
c
,
int
nBytes
)
{
PrintMessage
(
c
,
"reçu de "
,
nBytes
);
}
public
static
void
PrintMessage
(
ChatMessage
c
,
string
action
,
int
nBytes
)
{
PrintMessage
(
c
,
""
,
action
,
nBytes
);
}
public
static
void
PrintMessage
(
ChatMessage
c
,
string
nomMessage
,
string
action
,
int
nBytes
)
{
Console
.
WriteLine
(
""
);
Console
.
Write
(
"Nouveau message "
+
nomMessage
);
Console
.
ForegroundColor
=
ConsoleColor
.
Green
;
Console
.
Write
(
action
);
Console
.
ForegroundColor
=
ConsoleColor
.
White
;
Console
.
WriteLine
(
serverEP
+
" ("
+
nBytes
+
" octets)"
+
": \""
+
c
+
"\""
);
}
}
}
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp/Properties/AssemblyInfo.cs
View file @
6a939fae
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[
assembly
:
AssemblyTitle
(
"clientUdp"
)]
[
assembly
:
AssemblyDescription
(
""
)]
[
assembly
:
AssemblyConfiguration
(
""
)]
[
assembly
:
AssemblyCompany
(
"Microsoft"
)]
[
assembly
:
AssemblyProduct
(
"clientUdp"
)]
[
assembly
:
AssemblyCopyright
(
"Copyright © Microsoft 2011"
)]
[
assembly
:
AssemblyTrademark
(
""
)]
[
assembly
:
AssemblyCulture
(
""
)]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[
assembly
:
ComVisible
(
false
)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[
assembly
:
Guid
(
"96a16382-fd5c-499c-a83b-b5a0e2a08417"
)]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[
assembly
:
AssemblyVersion
(
"1.0.0.0"
)]
[
assembly
:
AssemblyFileVersion
(
"1.0.0.0"
)]
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[
assembly
:
AssemblyTitle
(
"clientUdp"
)]
[
assembly
:
AssemblyDescription
(
""
)]
[
assembly
:
AssemblyConfiguration
(
""
)]
[
assembly
:
AssemblyCompany
(
"Microsoft"
)]
[
assembly
:
AssemblyProduct
(
"clientUdp"
)]
[
assembly
:
AssemblyCopyright
(
"Copyright © Microsoft 2011"
)]
[
assembly
:
AssemblyTrademark
(
""
)]
[
assembly
:
AssemblyCulture
(
""
)]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[
assembly
:
ComVisible
(
false
)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[
assembly
:
Guid
(
"96a16382-fd5c-499c-a83b-b5a0e2a08417"
)]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[
assembly
:
AssemblyVersion
(
"1.0.0.0"
)]
[
assembly
:
AssemblyFileVersion
(
"1.0.0.0"
)]
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp/bin/Debug/clientUdp.exe
deleted
100644 → 0
View file @
028faecf
File deleted
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp/bin/Debug/clientUdp.pdb
deleted
100644 → 0
View file @
028faecf
File deleted
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp/clientUdp.csproj
View file @
6a939fae
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"4.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
x86
</Platform>
<ProductVersion>
8.0.30703
</ProductVersion>
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
clientUdp
</RootNamespace>
<AssemblyName>
clientUdp
</AssemblyName>
<TargetFrameworkVersion>
v4.0
</TargetFrameworkVersion>
<TargetFrameworkProfile>
Client
</TargetFrameworkProfile>
<FileAlignment>
512
</FileAlignment>
<PublishUrl>
publish\
</PublishUrl>
<Install>
true
</Install>
<InstallFrom>
Disk
</InstallFrom>
<UpdateEnabled>
false
</UpdateEnabled>
<UpdateMode>
Foreground
</UpdateMode>
<UpdateInterval>
7
</UpdateInterval>
<UpdateIntervalUnits>
Days
</UpdateIntervalUnits>
<UpdatePeriodically>
false
</UpdatePeriodically>
<UpdateRequired>
false
</UpdateRequired>
<MapFileExtensions>
true
</MapFileExtensions>
<ApplicationRevision>
0
</ApplicationRevision>
<ApplicationVersion>
1.0.0.%2a
</ApplicationVersion>
<IsWebBootstrapper>
false
</IsWebBootstrapper>
<UseApplicationTrust>
false
</UseApplicationTrust>
<BootstrapperEnabled>
true
</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|x86' "
>
<PlatformTarget>
x86
</PlatformTarget>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|x86' "
>
<PlatformTarget>
x86
</PlatformTarget>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Xml.Linq"
/>
<Reference
Include=
"System.Data.DataSetExtensions"
/>
<Reference
Include=
"Microsoft.CSharp"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"..\..\ChatMessage.cs"
>
<Link>
ChatMessage.cs
</Link>
</Compile>
<Compile
Include=
"ClientUdp.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage
Include=
".NETFramework,Version=v4.0,Profile=Client"
>
<Visible>
False
</Visible>
<ProductName>
Microsoft .NET Framework 4 Client Profile %28x86 et x64%29
</ProductName>
<Install>
true
</Install>
</BootstrapperPackage>
<BootstrapperPackage
Include=
"Microsoft.Net.Client.3.5"
>
<Visible>
False
</Visible>
<ProductName>
.NET Framework 3.5 SP1 Client Profile
</ProductName>
<Install>
false
</Install>
</BootstrapperPackage>
<BootstrapperPackage
Include=
"Microsoft.Net.Framework.3.5.SP1"
>
<Visible>
False
</Visible>
<ProductName>
.NET Framework 3.5 SP1
</ProductName>
<Install>
false
</Install>
</BootstrapperPackage>
<BootstrapperPackage
Include=
"Microsoft.Windows.Installer.3.1"
>
<Visible>
False
</Visible>
<ProductName>
Windows Installer 3.1
</ProductName>
<Install>
true
</Install>
</BootstrapperPackage>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"4.0"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
x86
</Platform>
<ProductVersion>
8.0.30703
</ProductVersion>
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{0F2D151A-DDD4-4AAD-8FAA-B58B6C4BE47E}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
clientUdp
</RootNamespace>
<AssemblyName>
clientUdp
</AssemblyName>
<TargetFrameworkVersion>
v4.0
</TargetFrameworkVersion>
<TargetFrameworkProfile>
Client
</TargetFrameworkProfile>
<FileAlignment>
512
</FileAlignment>
<PublishUrl>
publish\
</PublishUrl>
<Install>
true
</Install>
<InstallFrom>
Disk
</InstallFrom>
<UpdateEnabled>
false
</UpdateEnabled>
<UpdateMode>
Foreground
</UpdateMode>
<UpdateInterval>
7
</UpdateInterval>
<UpdateIntervalUnits>
Days
</UpdateIntervalUnits>
<UpdatePeriodically>
false
</UpdatePeriodically>
<UpdateRequired>
false
</UpdateRequired>
<MapFileExtensions>
true
</MapFileExtensions>
<ApplicationRevision>
0
</ApplicationRevision>
<ApplicationVersion>
1.0.0.%2a
</ApplicationVersion>
<IsWebBootstrapper>
false
</IsWebBootstrapper>
<UseApplicationTrust>
false
</UseApplicationTrust>
<BootstrapperEnabled>
true
</BootstrapperEnabled>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|x86' "
>
<PlatformTarget>
x86
</PlatformTarget>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|x86' "
>
<PlatformTarget>
x86
</PlatformTarget>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
/>
<Reference
Include=
"System.Xml.Linq"
/>
<Reference
Include=
"System.Data.DataSetExtensions"
/>
<Reference
Include=
"Microsoft.CSharp"
/>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"..\..\ChatMessage.cs"
>
<Link>
ChatMessage.cs
</Link>
</Compile>
<Compile
Include=
"ClientUdp.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
<BootstrapperPackage
Include=
".NETFramework,Version=v4.0,Profile=Client"
>
<Visible>
False
</Visible>
<ProductName>
Microsoft .NET Framework 4 Client Profile %28x86 et x64%29
</ProductName>
<Install>
true
</Install>
</BootstrapperPackage>
<BootstrapperPackage
Include=
"Microsoft.Net.Client.3.5"
>
<Visible>
False
</Visible>
<ProductName>
.NET Framework 3.5 SP1 Client Profile
</ProductName>
<Install>
false
</Install>
</BootstrapperPackage>
<BootstrapperPackage
Include=
"Microsoft.Net.Framework.3.5.SP1"
>
<Visible>
False
</Visible>
<ProductName>
.NET Framework 3.5 SP1
</ProductName>
<Install>
false
</Install>
</BootstrapperPackage>
<BootstrapperPackage
Include=
"Microsoft.Windows.Installer.3.1"
>
<Visible>
False
</Visible>
<ProductName>
Windows Installer 3.1
</ProductName>
<Install>
true
</Install>
</BootstrapperPackage>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp/obj/x86/Debug/DesignTimeResolveAssemblyReferencesInput.cache
deleted
100644 → 0
View file @
028faecf
File deleted
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp/obj/x86/Debug/clientUdp.csproj.CoreCompileInputs.cache
deleted
100644 → 0
View file @
028faecf
32902e1961b84f10fe4818911d10801d1ba3d30c
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp/obj/x86/Debug/clientUdp.csprojAssemblyReference.cache
deleted
100644 → 0
View file @
028faecf
File deleted
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp/obj/x86/Debug/clientUdp.exe
deleted
100644 → 0
View file @
028faecf
File deleted
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp/obj/x86/Debug/clientUdp.pdb
deleted
100644 → 0
View file @
028faecf
File deleted
This diff is collapsed.
Click to expand it.
Chat/clientUdp/clientUdp/obj/x86/Release/clientUdp.csproj.CoreCompileInputs.cache
deleted
100644 → 0
View file @
028faecf
c8d3b2f32916d9314a2097dcb766dd824d44e031
This diff is collapsed.
Click to expand it.
Chat/serveurUdp/serveurUdp.sln
View file @
6a939fae
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2018
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "serveurUdp", "serveurUdp\serveurUdp.csproj", "{7FD485EB-1D1E-4208-868C-5994E555E8AE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7FD485EB-1D1E-4208-868C-5994E555E8AE}.Debug|x86.ActiveCfg = Debug|x86
{7FD485EB-1D1E-4208-868C-5994E555E8AE}.Debug|x86.Build.0 = Debug|x86
{7FD485EB-1D1E-4208-868C-5994E555E8AE}.Release|x86.ActiveCfg = Release|x86
{7FD485EB-1D1E-4208-868C-5994E555E8AE}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6790DBDC-DA79-4222-A40D-C6C68E77E66A}
EndGlobalSection
EndGlobal
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.27703.2018
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "serveurUdp", "serveurUdp\serveurUdp.csproj", "{7FD485EB-1D1E-4208-868C-5994E555E8AE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x86 = Debug|x86
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7FD485EB-1D1E-4208-868C-5994E555E8AE}.Debug|x86.ActiveCfg = Debug|x86
{7FD485EB-1D1E-4208-868C-5994E555E8AE}.Debug|x86.Build.0 = Debug|x86
{7FD485EB-1D1E-4208-868C-5994E555E8AE}.Release|x86.ActiveCfg = Release|x86
{7FD485EB-1D1E-4208-868C-5994E555E8AE}.Release|x86.Build.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {6790DBDC-DA79-4222-A40D-C6C68E77E66A}
EndGlobalSection
EndGlobal
This diff is collapsed.
Click to expand it.
Chat/serveurUdp/serveurUdp/Properties/AssemblyInfo.cs
View file @
6a939fae
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[
assembly
:
AssemblyTitle
(
"serveurUdp"
)]
[
assembly
:
AssemblyDescription
(
""
)]
[
assembly
:
AssemblyConfiguration
(
""
)]
[
assembly
:
AssemblyCompany
(
"Microsoft"
)]
[
assembly
:
AssemblyProduct
(
"serveurUdp"
)]
[
assembly
:
AssemblyCopyright
(
"Copyright © Microsoft 2011"
)]
[
assembly
:
AssemblyTrademark
(
""
)]
[
assembly
:
AssemblyCulture
(
""
)]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[
assembly
:
ComVisible
(
false
)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[
assembly
:
Guid
(
"c5b04a06-a37d-4987-a728-b25343d9915f"
)]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[
assembly
:
AssemblyVersion
(
"1.0.0.0"
)]
[
assembly
:
AssemblyFileVersion
(
"1.0.0.0"
)]
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
// Les informations générales relatives à un assembly dépendent de
// l'ensemble d'attributs suivant. Changez les valeurs de ces attributs pour modifier les informations
// associées à un assembly.
[
assembly
:
AssemblyTitle
(
"serveurUdp"
)]
[
assembly
:
AssemblyDescription
(
""
)]
[
assembly
:
AssemblyConfiguration
(
""
)]
[
assembly
:
AssemblyCompany
(
"Microsoft"
)]
[
assembly
:
AssemblyProduct
(
"serveurUdp"
)]
[
assembly
:
AssemblyCopyright
(
"Copyright © Microsoft 2011"
)]
[
assembly
:
AssemblyTrademark
(
""
)]
[
assembly
:
AssemblyCulture
(
""
)]
// L'affectation de la valeur false à ComVisible rend les types invisibles dans cet assembly
// aux composants COM. Si vous devez accéder à un type dans cet assembly à partir de
// COM, affectez la valeur true à l'attribut ComVisible sur ce type.
[
assembly
:
ComVisible
(
false
)]
// Le GUID suivant est pour l'ID de la typelib si ce projet est exposé à COM
[
assembly
:
Guid
(
"c5b04a06-a37d-4987-a728-b25343d9915f"
)]
// Les informations de version pour un assembly se composent des quatre valeurs suivantes :
//
// Version principale
// Version secondaire
// Numéro de build
// Révision
//
// Vous pouvez spécifier toutes les valeurs ou indiquer les numéros de build et de révision par défaut
// en utilisant '*', comme indiqué ci-dessous :
// [assembly: AssemblyVersion("1.0.*")]
[
assembly
:
AssemblyVersion
(
"1.0.0.0"
)]
[
assembly
:
AssemblyFileVersion
(
"1.0.0.0"
)]
This diff is collapsed.
Click to expand it.
Chat/serveurUdp/serveurUdp/ServeurUdp.cs
View file @
6a939fae
using
System
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.IO
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
ClientUdp
;
namespace
ServeurUdp
{
class
ServeurUdp
{
//Liste de ChatMessage dans laquelle les ChatMessages reçus par POST sont stockés
static
List
<
ChatMessage
>
listeMessages
=
new
List
<
ChatMessage
>();
//Liste d'EndPoint dans laquelle les personnes inscrites sont stockées sous la forme: <EndPoint,pseudo>
static
Dictionary
<
EndPoint
,
string
>
listeAbonnes
=
new
Dictionary
<
EndPoint
,
string
>();
static
Socket
serverSocket
;
static
EndPoint
clientEP
;
static
void
Main
(
string
[]
args
)
{
try
{
// ************************************************************** Initialisation
// Création de la socket d'écoute UDP
serverSocket
=
new
Socket
(
AddressFamily
.
InterNetwork
,
SocketType
.
Dgram
,
ProtocolType
.
Udp
);
// Liaison de la socket au point de communication
serverSocket
.
Bind
(
new
IPEndPoint
(
IPAddress
.
Any
,
11111
));
Boolean
run
=
true
;
while
(
run
)
{
//************************************************************** Communications
Console
.
WriteLine
(
""
);
Console
.
WriteLine
(
"Attente d'une nouveau message..."
);
// Reception message client
clientEP
=
new
IPEndPoint
(
IPAddress
.
Any
,
0
);
byte
[]
buffer
=
new
byte
[
1500
];
int
nBytes
=
serverSocket
.
ReceiveFrom
(
buffer
,
buffer
.
Length
,
SocketFlags
.
None
,
ref
clientEP
);
ChatMessage
chatMsg
=
null
;
try
{
chatMsg
=
new
ChatMessage
(
buffer
);
}
catch
(
ArgumentException
e
)
{
Console
.
WriteLine
(
"Erreur : "
+
e
.
Message
);
}
Console
.
WriteLine
(
"Nouveau message de "
+
clientEP
+
" ("
+
nBytes
+
" octets)"
+
": \""
+
chatMsg
+
"\""
);
if
(
chatMsg
!=
null
)
{
//Regarde quelle méthode est envoyée pour envoyée le message
switch
(
chatMsg
.
commande
)
{
//Méthode POST
case
Commande
.
POST
:
StockerMessage
(
chatMsg
);
break
;
//Méthode GET
case
Commande
.
GET
:
RecevoirMessage
(
chatMsg
);
break
;
//Méthode HELP
case
Commande
.
HELP
:
break
;
//Méthode QUIT
case
Commande
.
QUIT
:
break
;
//Méthode STOPSERVEUR
case
Commande
.
STOPSERVEUR
:
run
=
false
;
break
;
//Méthode SUBSCRIBE
case
Commande
.
SUBSCRIBE
:
SubscribeClient
(
chatMsg
,
clientEP
);
break
;
//Méthode SUBSCRIBEv2
case
Commande
.
SUBSCRIBEv2
:
break
;
//Méthode UNSUBSCRIBE
case
Commande
.
UNSUBSCRIBE
:
break
;
}
}
}
Console
.
WriteLine
(
"Appuyez sur une touche pour quitter..."
);
Console
.
ReadKey
();
}
catch
(
SocketException
E
)
{
Console
.
WriteLine
(
E
.
Message
);
}
finally
using
System
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.IO
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
ClientUdp
;
namespace
ServeurUdp
{
class
ServeurUdp
{
static
List
<
ChatMessage
>
listeMessages
=
new
List
<
ChatMessage
>();
//Liste d'EndPoint dans laquelle les personnes inscrites sont stockées sous la forme: <EndPoint,pseudo>
static
Dictionary
<
EndPoint
,
string
>
listeAbonnes
=
new
Dictionary
<
EndPoint
,
string
>();
/* Dictionnaire représentant toutes les rooms, et comprenant:
- en clé le nom de la room
- en valeur la liste des ChatMessages reçus par POST dans cette room.
*/
static
Dictionary
<
string
,
List
<
ChatMessage
>>
listeRooms
=
new
Dictionary
<
string
,
List
<
ChatMessage
>>();
static
Socket
serverSocket
;
static
EndPoint
clientEP
;
static
void
Main
(
string
[]
args
)
{
try
{
// ************************************************************** Initialisation
// Création de la socket d'écoute UDP
serverSocket
=
new
Socket
(
AddressFamily
.
InterNetwork
,
SocketType
.
Dgram
,
ProtocolType
.
Udp
);
// Liaison de la socket au point de communication
serverSocket
.
Bind
(
new
IPEndPoint
(
IPAddress
.
Any
,
11111
));
Boolean
run
=
true
;
while
(
run
)
{
//************************************************************** Communications
Console
.
WriteLine
(
""
);
Console
.
WriteLine
(
"Attente d'une nouveau message..."
);
// Reception message client
clientEP
=
new
IPEndPoint
(
IPAddress
.
Any
,
0
);
byte
[]
buffer
=
new
byte
[
1500
];
int
nBytes
=
serverSocket
.
ReceiveFrom
(
buffer
,
buffer
.
Length
,
SocketFlags
.
None
,
ref
clientEP
);
ChatMessage
chatMsg
=
null
;
try
{
chatMsg
=
new
ChatMessage
(
buffer
);
}
catch
(
ArgumentException
e
)
{
Console
.
WriteLine
(
"Erreur : "
+
e
.
Message
);
}
Console
.
WriteLine
(
"Nouveau message de "
+
clientEP
+
" ("
+
nBytes
+
" octets)"
+
": \""
+
chatMsg
+
"\""
);
if
(
chatMsg
!=
null
)
{
//Regarde quelle méthode est envoyée pour envoyée le message
switch
(
chatMsg
.
commande
)
{
//Méthode POST
case
Commande
.
POST
:
StockerMessage
(
chatMsg
);
break
;
//Méthode GET
case
Commande
.
GET
:
RecevoirMessage
(
chatMsg
);
break
;
//Méthode HELP
case
Commande
.
HELP
:
break
;
//Méthode QUIT
case
Commande
.
QUIT
:
break
;
//Méthode STOPSERVEUR
case
Commande
.
STOPSERVEUR
:
run
=
false
;
break
;
//Méthode SUBSCRIBE
case
Commande
.
SUBSCRIBE
:
SubscribeClient
(
chatMsg
,
clientEP
);
break
;
//Méthode SUBSCRIBEv2
case
Commande
.
SUBSCRIBEv2
:
break
;
//Méthode UNSUBSCRIBE
case
Commande
.
UNSUBSCRIBE
:
break
;
/*case Commande.CREATEROOM:
//CreateRoom(chatMsg);
break;
case Commande.LISTROOMS:
//ListerRoom();
break;*/
}
}
}
}
catch
(
SocketException
E
)
{
Console
.
WriteLine
(
E
.
Message
);
}
finally
{
//En cas d'erreur ou à la fin, on ferme la socket et on arrete le thread de reception
Console
.
WriteLine
(
""
);
Console
.
WriteLine
(
"Fermeture Socket"
);
serverSocket
.
Close
();
}
}
public
static
void
StockerMessage
(
ChatMessage
c
)
{
listeMessages
.
Add
(
c
);
Console
.
WriteLine
(
"Le message '"
+
c
.
ToString
()
+
"a été stocké"
);
foreach
(
KeyValuePair
<
EndPoint
,
String
>
abonne
in
listeAbonnes
)
{
serverSocket
.
SendTo
(
ChatMessage
.
GetBytes
(
Commande
.
SUBSCRIBE
,
CommandeType
.
REPONSE
,
c
.
pseudo
,
c
.
data
),
abonne
.
Key
);
}
}
public
static
void
RecevoirMessage
(
ChatMessage
c
)
{
foreach
(
ChatMessage
message
in
listeMessages
)
{
serverSocket
.
SendTo
(
ChatMessage
.
GetBytes
(
Commande
.
GET
,
CommandeType
.
REPONSE
,
message
.
pseudo
,
message
.
data
),
clientEP
);
}
}
public
static
void
SubscribeClient
(
ChatMessage
c
,
EndPoint
ep
)
{
if
(!
listeAbonnes
.
ContainsKey
(
ep
))
{
listeAbonnes
.
Add
(
ep
,
c
.
pseudo
);
Console
.
WriteLine
(
c
.
pseudo
+
" vient de s'abonner"
);
}
else
Console
.
WriteLine
(
"Le client est déjà enregistré pour recevoir les messages"
);
}
public
static
void
UnsubscribeClient
(
ChatMessage
c
,
EndPoint
clientEP
)
{
if
(
listeAbonnes
.
ContainsKey
(
clientEP
))
{
listeAbonnes
.
Remove
(
clientEP
);
Console
.
WriteLine
(
c
.
pseudo
+
" vient de se desabonner"
);
}
else
{
Console
.
WriteLine
(
"Le client n'est pas enregistré pour recevoir de messages"
);
}
}
}
serverSocket
.
Close
();
Console
.
WriteLine
(
"Appuyez sur une touche pour quitter..."
);
Console
.
ReadKey
();
}
}
public
static
void
StockerMessage
(
ChatMessage
c
)
{
listeMessages
.
Add
(
c
);
Console
.
WriteLine
(
"Le message '"
+
c
.
ToString
()
+
"a été stocké"
);
foreach
(
KeyValuePair
<
EndPoint
,
String
>
abonne
in
listeAbonnes
)
{
serverSocket
.
SendTo
(
ChatMessage
.
GetBytes
(
Commande
.
SUBSCRIBE
,
CommandeType
.
REPONSE
,
c
.
pseudo
,
c
.
data
),
abonne
.
Key
);
}
}
public
static
void
RecevoirMessage
(
ChatMessage
c
)
{
foreach
(
ChatMessage
message
in
listeMessages
)
{
serverSocket
.
SendTo
(
ChatMessage
.
GetBytes
(
Commande
.
GET
,
CommandeType
.
REPONSE
,
message
.
pseudo
,
message
.
data
),
clientEP
);
}
}
public
static
void
SubscribeClient
(
ChatMessage
c
,
EndPoint
ep
)
{
if
(!
listeAbonnes
.
ContainsKey
(
ep
))
{
listeAbonnes
.
Add
(
ep
,
c
.
pseudo
);
Console
.
WriteLine
(
c
.
pseudo
+
" vient de s'abonner"
);
}
else
Console
.
WriteLine
(
"Le client est déjà enregistré pour recevoir les messages"
);
}
public
static
void
UnsubscribeClient
(
ChatMessage
c
,
EndPoint
clientEP
)
{
if
(
listeAbonnes
.
ContainsKey
(
clientEP
))
{
listeAbonnes
.
Remove
(
clientEP
);
Console
.
WriteLine
(
c
.
pseudo
+
" vient de se desabonner"
);
}
else
{
Console
.
WriteLine
(
"Le client n'est pas enregistré pour recevoir de messages"
);
}
}
public
static
void
CreateRoom
(
ChatMessage
c
)
{
if
(!
listeRooms
.
ContainsKey
(
c
.
data
)){
List
<
ChatMessage
>
lMessages
=
new
List
<
ChatMessage
>();
listeRooms
.
Add
(
c
.
data
,
lMessages
);
Console
.
WriteLine
(
"la room "
+
c
.
data
+
" vient d'etre creer"
);
}
else
Console
.
WriteLine
(
"La room existe déjà"
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Chat/serveurUdp/serveurUdp/bin/Debug/serveurUdp.exe
deleted
100644 → 0
View file @
028faecf
File deleted
This diff is collapsed.
Click to expand it.
Chat/serveurUdp/serveurUdp/bin/Debug/serveurUdp.pdb
deleted
100644 → 0
View file @
028faecf
File deleted
This diff is collapsed.
Click to expand it.
Prev
1
2
3
4
5
Next
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment