using
System;
using
System.Net;
using
System.Net.Sockets;
using
System.Text;
using
System.Configuration;
class
StudentUDPServer
{
public
static
void
Main()
{
UdpClient udpc =
new
UdpClient(7878);
Console.WriteLine(
"Server Started, servicing on port no. 7878"
);
IPEndPoint ep =
null
;
while
(
true
){
byte
[] receivedData = udpc.Receive(
ref
ep);
string
studentName = Encoding.ASCII.GetString(receivedData);
string
msg = ConfigurationSettings.AppSettings[studentName];
if
(msg ==
null
) msg =
"No such Student available for conversation"
;
byte
[] sdata = Encoding.ASCII.GetBytes(msg);
udpc.Send(sdata, sdata.Length, ep);
}
}
}
using
System;
using
System.Net;
using
System.Net.Sockets;
using
System.Text;
class
StudentUDPClient
{
public
static
void
Main(
string
[] args)
{
UdpClient udpc =
new
UdpClient(
"PC_NAME"
, 7878);
IPEndPoint ep =
null
;
while
(
true
)
{
Console.Write(
"Enter Your Name: "
);
string
studentName = Console.ReadLine();
if
(studentName ==
""
){
Console.Write(
"You did not enter your name. Closing..."
);
break
;
}
byte
[] msg = Encoding.ASCII.GetBytes(studentName);
udpc.Send(msg, msg.Length);
byte
[] rdata = udpc.Receive(
ref
ep);
string
job = Encoding.ASCII.GetString(rdata);
Console.WriteLine(job);
}
}
}