using
System;using
System.Net;using System.Net.Sockets;
class
EmployeeSrvr{
public static void Main(){
byte[] data = new byte[1024]; IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050); UdpClient newsock = new UdpClient(ipep); Console.WriteLine("Waiting for a client..."); IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); for (; ; ){
data = newsock.Receive(
ref sender); Employee emp1 = new Employee(data); Console.WriteLine("{0} {1} {2} {3}", emp1.EmployeeID, emp1.LastName, emp1.FirstName, emp1.YearsService, emp1.Salary);}
}
}
EmployeeClient
using
System;using
System.Net;using
System.Net.Sockets;class
EmployeeClient{
public static void Main(){
Employee emp1 = new Employee(); String ip;ip=
Console.ReadLine();emp1.EmployeeID = 2105;
emp1.LastName =
"Yossawat";emp1.FirstName =
"Wongchan";emp1.YearsService = 50;
UdpClient server = new UdpClient(ip, 9050); IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0); byte[] data = emp1.GetBytes();server.Send(data, data.Length);
}
}
using
System;using
System.Text;class
Employee{
public int EmployeeID; private int LastNameSize; public string LastName; private int FirstNameSize; public string FirstName; public string Id; private int IdSize; public double Salary; public int size; public Employee(){
}
public Employee(byte[] data){
int place = 0;EmployeeID =
BitConverter.ToInt32(data, place);place += 4;
LastNameSize =
BitConverter.ToInt32(data, place);place += 4;
LastName =
Encoding.ASCII.GetString(data, place, LastNameSize);place = place + LastNameSize;
FirstNameSize =
BitConverter.ToInt32(data, place);place += 4;
FirstName =
Encoding.ASCII.GetString(data, place, FirstNameSize);place += FirstNameSize;
IdSize =
BitConverter.ToInt32(data, place);place += 4;
Id =
Encoding.ASCII.GetString(data, place, IdSize);place += IdSize;
Salary =
BitConverter.ToDouble(data, place);}
public byte[] GetBytes(){
place += 4;
Buffer.BlockCopy(BitConverter.GetBytes(LastName.Length), 0, data, place, 4);
place += 4;
Buffer.BlockCopy(Encoding.ASCII.GetBytes(LastName), 0, data, place, LastName.Length);
place += LastName.Length;
Buffer.BlockCopy(BitConverter.GetBytes(FirstName.Length), 0, data, place, 4);
place += 4;
Buffer.BlockCopy(Encoding.ASCII.GetBytes(FirstName), 0, data, place, FirstName.Length);
place += FirstName.Length;
Buffer.BlockCopy(BitConverter.GetBytes(Id.Length), 0, data, place, 4);
place += 4;
Buffer.BlockCopy(Encoding.ASCII.GetBytes(Id), 0, data, place, Id.Length);
place += Id.Length;
Buffer.BlockCopy(BitConverter.GetBytes(Salary), 0, data, place, 8);place += 8;
size = place;
return data;}
}
using
System;using
System.Net;using
System.Net.Sockets;class
{
public static void Main(){
Employee emp1 = new Employeeemp1.EmployeeID = 1;
emp1.LastName =
"Wassayapalin";emp1.FirstName =
"Alongkone";emp1.Id =
"5066262311";emp1.Salary = 30000;
String ip;ip =
Console.ReadLine(); byte[] data = emp1.GetBytes(); UdpClient server = new UdpClient(ip, 9050);server.Send(data, data.Length);
}
}
empsever.cs
using
System;using
System.Net;using
System.Net.Sockets;class
{
public static void Main(){
byte[] data = new byte[1024]; IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050); UdpClient newsock = new UdpClient(ipep);{
data = newsock.Receive(
ref sender); Employee emp1 = new Employee(data); Console.WriteLine("{0} {1} {2} {3} ", emp1.EmployeeID, emp1.LastName, emp1.FirstName, emp1.Id, emp1.Salary);}
}
}
using
System;using
System.Net;using
System.Net.Sockets;class
EmployeeSrvr{
public static void Main(){
byte[] data = new byte[1024];IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050); UdpClient newsock = new UdpClient(ipep); Console.WriteLine("Waiting for a client..."); IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
{
data = newsock.Receive(
Employee emp1 = new Employee(data);
}
}
}
using
System;using
System.Net;using
System.Net.Sockets;class
EmployeeClient{
public static void Main(){
Employee emp1 = new Employee();emp1.EmployeeID = 1;
emp1.LastName =
emp1.FirstName =
"JIB";emp1.YearsService = 12;
emp1.Salary = 55000;
data = emp1.GetBytes();
server.Send(data, data.Length);
}
}
ส่งาน EmployeeUDPClient and EmployeeUDPServer
EmployeeSrvr
using System;
using System.Net;
using System.Net.Sockets;
class EmployeeSrvr
{
public static void Main()
{
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
UdpClient newsock = new UdpClient(ipep);
while (true)
{
Console.WriteLine("Waiting for a client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
data = newsock.Receive(ref sender);
byte[] size = new byte[2];
int packsize = BitConverter.ToInt16(size, 0);
Console.WriteLine("packet size = {0}", packsize);
Employee emp1 = new Employee(data);
Console.WriteLine("emp1.EmployeeID = {0}", emp1.EmployeeID);
Console.WriteLine("emp1.LastName = {0}", emp1.LastName);
Console.WriteLine("emp1.FirstName = {0}", emp1.FirstName);
Console.WriteLine("emp1.YearsService = {0}", emp1.YearsService);
Console.WriteLine("emp1.Salary = {0}\n", emp1.Salary);
}
}
}
EmployeeClient
using System;
using System.Net;
using System.Net.Sockets;
class EmployeeClient
{
public static void Main()
{
Employee emp1 = new Employee();
UdpClient client;
emp1.EmployeeID = 1;
emp1.LastName = "seanlert";
emp1.FirstName = "Sukanya";
emp1.YearsService = 12;
emp1.Salary = 35000;
try
{
Console.Write("Enter IP :");
String IP = Console.ReadLine();
client = new UdpClient(IP, 9050);
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
}
catch (SocketException)
{
Console.WriteLine("Unable to connect to server");
return;
}
byte[] data = emp1.GetBytes();
int size = emp1.size;
byte[] packsize = new byte[2];
Console.WriteLine("packet size = {0}", size);
packsize = BitConverter.GetBytes(size);
client.Send(data,data.Length);
}
}
using
System;using
System.Net;using
System.Net.Sockets;class
EmployeeClient{
public static void Main(){
Employee emp1 =
new Employee();Employee emp2 =
newemp1.EmployeeID = 1;
emp1.LastName =
"Konjing";emp1.FirstName =
"Tapanapong";emp1.YearsService = 9;
emp1.Salary = 25000;
ip =
Console.ReadLine();UdpClient server =
IPEndPoint sender =
newserver.Send(data, data.Length);
}
}
using
System;using
System.Net;using
System.Net.Sockets;class
EmployeeSrvr{
public static void Main(){
IPEndPoint ipep =
UdpClient newsock =
new UdpClient(ipep); Console.WriteLine("Waiting for a client...");IPEndPoint sender =
new IPEndPoint(IPAddress.Any, 0); for (; ; ){
data = newsock.Receive(
ref sender);Employee emp1 =
new Employee(data);}
}
}
using System;
using System.Net;
using System.Net.Sockets;
class EmployeeSrvr
{
public static void Main()
{
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
UdpClient newsock = new UdpClient(ipep);
Console.WriteLine("\n Waiting for a client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
for ( ; ; )
{
data = newsock.Receive(ref sender);
Employee emp1 = new Employee(data);
Console.WriteLine("\n EmployeeID\t= {0}", emp1.EmployeeID);
Console.WriteLine(" FirstName\t= {0}", emp1.FirstName);
Console.WriteLine(" LastName\t= {0}", emp1.LastName);
Console.WriteLine(" YearsService\t= {0}", emp1.YearsService);
Console.WriteLine(" Salary\t\t= {0}\n", emp1.Salary);
}
}
}
using System;
using System.Net;
using System.Net.Sockets;
class EmployeeClient
{
public static void Main()
{
String Ip;
Employee emp1 = new Employee();
emp1.EmployeeID = 2246;
emp1.LastName = "Meechao";
emp1.FirstName = "Pasakorn";
emp1.YearsService = 12;
emp1.Salary = 35000.55;
byte[] data = emp1.GetBytes();
Console.Write("\n IP Address : ");
Ip = Console.ReadLine();
UdpClient server = new UdpClient(Ip, 9050);
class EmployeeSrvr
{
public static void Main()
{
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
UdpClient newsock = new UdpClient(ipep);
while(true){
Console.WriteLine("Waiting for a client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
data = newsock.Receive(ref sender);
byte[] size = new byte[2];
int packsize = BitConverter.ToInt16(size, 0);
Console.WriteLine("packet size = {0}", packsize);
Employee emp1 = new Employee(data);
Console.WriteLine("emp1.EmployeeID = {0}", emp1.EmployeeID);
Console.WriteLine("emp1.LastName = {0}", emp1.LastName);
Console.WriteLine("emp1.FirstName = {0}", emp1.FirstName);
Console.WriteLine("emp1.YearsService = {0}", emp1.YearsService);
Console.WriteLine("emp1.Salary = {0}\n", emp1.Salary);
}
}
}
class EmployeeClient
{
public static void Main()
{
Employee emp1 = new Employee();
UdpClient server;
emp1.EmployeeID = 1;
emp1.LastName = "Deetakulwattanapon";
emp1.FirstName = "Nuttakorn";
emp1.YearsService = 99;
emp1.Salary = 85000;
try
{
Console.Write("Enter Destination IP : ");
String IP = Console.ReadLine();
server = new UdpClient(IP, 9050);
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
}
catch (SocketException)
{
Console.WriteLine("Unable to connect to server");
return;
}
byte[] data = emp1.GetBytes();
int size = emp1.size;
byte[] packsize = new byte[2];
Console.WriteLine("packet size = {0}", size);
//packsize = BitConverter.GetBytes(size);
server.Send(data, data.Length);
using
System;using
System.Net;using
System.Net.Sockets;using
System.Text;class
EmployeeSrvr{
public static void Main(){
{
data = newsock.Receive(
ref sender); //Console.WriteLine(Encoding.ASCII.GetString(data,0,data.Length));}
}
}
EmployeeClient.cs
using
System;using
System.Net;using
System.Net.Sockets;using
System.Text;class
EmployeeClient{
public static void Main(){
Employee emp1 = new Employee();emp1.EmployeeID = 1057;
emp1.LastName =
"Wuttiprapakul";emp1.FirstName =
"Papontee";emp1.YearsService = 12;
emp1.Salary = 35000.50;
try{
Console.Write("Enter IP Server : "); string ip = Console.ReadLine();client =
new UdpClient(ip, 9050);}
{
}
byte[] data = emp1.GetBytes();client.Send(data,data.Length);
client.Close();
}
}
Server
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
class EmployeeSrvr
{
public static void Main()
{
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
UdpClient newsock = new UdpClient(ipep);
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
while (true)
{
Console.WriteLine("Waiting for a client...");
data = new byte[1024];
data = newsock.Receive(ref sender);
Console.WriteLine("Message received from {0}:", sender.ToString());
int packsize = BitConverter.ToInt16(data, 0);
Console.WriteLine("packet size = {0}", packsize);
data = new byte[1024];
data = newsock.Receive(ref sender);
Employee emp1 = new Employee(data);
Console.WriteLine("emp1.EmployeeID = {0}", emp1.EmployeeID);
Console.WriteLine("emp1.LastName = {0}", emp1.LastName);
Console.WriteLine("emp1.FirstName = {0}", emp1.FirstName);
Console.WriteLine("emp1.Salary = {0}\n", emp1.Salary);
}
}
}
Client
using System;
using System.Net;
using System.Net.Sockets;
class EmployeeClient
{
public static void Main()
{
Employee emp1 = new Employee();
emp1.EmployeeID = 3541;
emp1.LastName = "Jinseang";
emp1.FirstName = "Piyawat";
emp1.Salary = 50000;
while (true)
{
Console.Write("IP : ");
string ipp = Console.ReadLine();
IPEndPoint ipep = new IPEndPoint(
IPAddress.Parse(ipp), 9050);
Socket server = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
byte[] data = emp1.GetBytes();
int size = emp1.size;
byte[] packsize = new byte[2];
Console.WriteLine("packet size = {0}", size);
packsize = BitConverter.GetBytes(size);
server.SendTo(packsize, 2, SocketFlags.None, ipep);
server.SendTo(data, size, SocketFlags.None, ipep);
}
}
}
using
System;using
System.Net;using
System.Net.Sockets;class
EmployeeSrvr{
public static void Main(){
byte[] data = new byte[1024]; IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050); UdpClient newsock = new UdpClient(ipep); Console.WriteLine("Waiting for a client..."); IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);{
data = newsock.Receive(
ref sender);}
newsock.Close();
}
}
//employee
using
System;using
System.Text;class
Employee{
{
}
public Employee(byte[] data){
intEmployeeIDsize =
BitConverter.ToInt32(data, place);place += 4;
EmployeeID =
Encoding.ASCII.GetString(data, place, EmployeeIDsize);place += EmployeeIDsize;
LastNameSize =
place += 4;
LastName =
Encoding.ASCII.GetString(data, place, LastNameSize);place = place + LastNameSize;
FirstNameSize =
BitConverter.ToInt32(data, place);place += 4;
FirstName =
Encodingplace += FirstNameSize;
Salary =
}
public byte[] GetBytes(){
EmployeeID.Length), 0, data, place, 4);
place += 4;
Buffer.BlockCopy(Encoding.ASCII.GetBytes(EmployeeID), 0, data, place, EmployeeID.Length);
place += EmployeeID.Length;
LastName.Length), 0, data, place, 4);
place += 4;
Buffer.BlockCopy(Encoding.ASCII.GetBytes(LastName), 0, data, place, LastName.Length);
place += LastName.Length;
Buffer.BlockCopy(BitConverter.GetBytes(FirstName.Length), 0, data, place, 4);
place += 4;
Buffer.BlockCopy(Encoding.ASCII.GetBytes(FirstName), 0, data, place, FirstName.Length);
place += FirstName.Length;
place += 8;
return data;}
}
//client udp
using
System;using
System.Net;using
System.Net.Sockets;class
EmployeeClient{
public static void Main(){
Employee emp1 = new Employee();emp1.EmployeeID =
"5066260067";emp1.LastName =
"Teerasak";emp1.FirstName =
"Kijmana";emp1.Salary = 35000.50;
try{
ip2 =
Console.ReadLine();server =
new UdpClient(ip2,9050);data = emp1.GetBytes();
server.Send(data,data.Length);
}
catch (SocketException){
}
server.Close();
}
}
using System.Net;
using System.Net.Sockets;
namespace EmployeeClient
{
class Program
{
public static void Main()
{
Employee emp1 = new Employee();
catch (SocketException)
{
Console.WriteLine("Unable to connect to server");
return;
}
byte[] data = emp1.GetBytes();
int size = emp1.size;
byte[] packsize = new byte[2];
Console.WriteLine("packet size = {0}", size);
packsize = BitConverter.GetBytes(size);
client.Send(data, data.Length);
}
}
}
Server
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace EmployeeSrvr
{
class Program
{
public static void Main()
{
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
UdpClient newsock = new UdpClient(ipep);
while (true)
{
Console.WriteLine("Waiting for a client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
data = newsock.Receive(ref sender);
byte[] size = new byte[2];
int packsize = BitConverter.ToInt16(size, 0);
Console.WriteLine("packet size = {0}", packsize);
Employee emp1 = new Employee(data);
Console.WriteLine("emp1.EmployeeID = {0}", emp1.EmployeeID);
Console.WriteLine("emp1.LastName = {0}", emp1.LastName);
Console.WriteLine("emp1.FirstName = {0}", emp1.FirstName);
Console.WriteLine("emp1.YearsService = {0}", emp1.YearsService);
Console.WriteLine("emp1.Salary = {0}\n", emp1.Salary);
size = new byte[2];
packsize = BitConverter.ToInt16(size, 0);
data = new byte[packsize];
Console.WriteLine("packet size = {0}", packsize);
}
}
}
}
using
System;using
System.Collections.Generic;using
System.Text;using
using
System.Net;namespace
ConsoleApplication3{
class Program{
static void Main(string[] args)
{
data = client.Receive(
ref end);}
}
}
/////////////////////////////////
EmployeeClient.cs
using
System;using
System.Collections.Generic;using
System.Text;using
System.Net;using
System.Net.Sockets;namespace
{
class Program
{
static void Main(string[] args)
{
emp1.EmployeeID = 1;
emp1.LastName =
"Nattapong Limprungpattanakit";emp1.FirstName =
"5066262154 IT-3RC";emp1.YearsService = 12;
emp1.Salary = 35000.50;
byte[] data = emp1.GetBytes(); UdpClient server = new UdpClient("127.0.0.1", 9050);server.Send(data, data.Length);
server.Close();
}
}
}
using
System;
using
System.Net;
using
System.Net.Sockets;
class
EmployeeSrvr
{
public static void Main(){
{
data = newsock.Receive(
ref sender); Employee emp1 = new Employee(data); Console.Write(" {0}", emp1.EmployeeID); Console.Write(" {0}", emp1.LastName); Console.Write(" {0}", emp1.FirstName); Console.Write(" {0}", emp1.YearsService); Console.Write(" {0}\n", emp1.Salary);}
}
}
Client
using
System;
using
System.Net;
using
System.Net.Sockets;
class
EmployeeClient
{
public static void Main(){
a =
Console.ReadLine(); Console.Write("Enter FirstName : ");b =
Console.ReadLine(); Console.Write("Enter YearsService : ");c =
Console.ReadLine(); Console.Write("Enter Salary : ");d =
Console.ReadLine();x =
Int32.Parse(c);y =
Double.Parse(d);emp1.EmployeeID = 1;
emp1.LastName =
a;
emp1.FirstName =
b;
emp1.YearsService = x;
emp1.Salary = y;
.Any, 0);
data = emp1.GetBytes();
server.Send(data, data.Length);
}
}
นายพงศกร ร้อยพุทธ
5066263558 IT3-RC
Server
using System;
using System.Net;
using System.Net.Sockets;
class EmployeeSrvr
{
public static void Main()
{
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9050);
UdpClient newsock = new UdpClient(ipep);
Console.WriteLine("Waiting for a client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
for (; ; )
{
data = newsock.Receive(ref sender);
Employee emp1 = new Employee(data);
Console.WriteLine("emp1.EmployeeID = {0}", emp1.EmployeeID);
Console.WriteLine("emp1.LastName = {0}", emp1.LastName);
Console.WriteLine("emp1.FirstName = {0}", emp1.FirstName);
Console.WriteLine("emp1.YearsService = {0}", emp1.YearsService);
Console.WriteLine("emp1.Salary = {0}\n", emp1.Salary);
}
}
}
Client
using System.Net;
using System.Net.Sockets;
class EmployeeClient
{
public static void Main()
{
Employee emp1 = new Employee();
string ip;
emp1.EmployeeID = 1;
emp1.LastName = "Blum";
emp1.FirstName = "Katie Jane";
emp1.YearsService = 12;
emp1.Salary = 35000.50;
Console.Write("IP : ");
ip = Console.ReadLine();
byte[] data = emp1.GetBytes();
UdpClient server = new UdpClient(ip, 9050);
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
server.Send(data, data.Length);
}
}