Documente Academic
Documente Profesional
Documente Cultură
d. Calculul distantei parcurse, daca se cunosc viteza initiala (m/s), timpul deplasării
(sec.) şi acceleratia(m/s2).
x = i % 2;
if (x != 0)
suma_impare = suma_impare + i;
if (x == 0)
{
suma_pare = suma_pare + i;
x = i % 7;
if (x == 0)
suma_div7 = suma_div7 + i;
totalno7 = totalno7 + 1;
Console.ReadLine();
Exercitii propuse:
1. Rescrieti programul c pentru transformarea temperaturii din grade Celsius in grade
Fahrenheit
2. Realizati modificarile necesare in programul d, astfel incat viteza sa fie introdusa in
kilometri pe ora, iar distanta sa fie afisata in kilometri
3. Realizati modificarile necesare in problema e pentru introducerea de la tastatura a
capetelor de interval. Se vor efectua aceleasi operatii, dar se va afisa in plus totalul
numerelor divizibile cu trei – dintre cele două capete de interval.
2. Structuri fundamentale de control, structure de date: vectori
unidimensionale
medie = calculeazaMedie(note);
Console.WriteLine("Note intre 1-4 : " + note1_4);
Console.WriteLine("Note intre 4-5 : " + note4_5);
Console.WriteLine("Note intre 5-6 : " + note5_6);
Console.WriteLine("Note intre 6-7 : " + note6_7);
Console.WriteLine("Note intre 7-8 : " + note7_8);
Console.WriteLine("Note intre 8-9 : " + note8_9);
Console.WriteLine("Note intre 9-10 : " + note9_10);
Console.WriteLine("Note imposibile : " + note_imposibile);
Console.WriteLine("Media notelor intre 1 si 10 varianta 1 este:
" + medie);
medie = calculeazaMedie_v2(note);
Console.WriteLine("Media notelor intre 1 si 10 varianta 2 este:
" + medie);
medie = calculeazaMedie_v3(8,10,note);
Console.WriteLine("Media notelor intre 8 si 10 este: " + medie);
Console.ReadLine();
}
// metoda 1 foreach
static float calculeazaMedie(float[] temp_vector)
{
float medie = 0;
int count = 0;
float suma_elemente = 0;
foreach (float f in temp_vector)
{
if (f >= 1 && f <= 10)
{
count++;
suma_elemente = suma_elemente + f;
}
}
medie = suma_elemente / count;
return medie;
}
// metoda 2: for
static float calculeazaMedie_v2(float[] temp_vector)
{
float medie = 0;
int count = 0;
float suma_elemente = 0;
for (int i = 0; i < temp_vector.Length; i++ )
{
if (temp_vector[i] >= 1 && temp_vector[i] <= 10)
{
count++;
suma_elemente = suma_elemente + temp_vector[i];
}
}
medie = suma_elemente / count;
return medie;
}
class Program
{
static void Main(string[] args)
{
# region declaratii_si_initializari_variabile
#endregion
second = third;
count = count + 1;
sum = sum + third;
}
while ((count + 3) <= no);
Console.WriteLine("\nSum of all fibonacci digits : " + sum);
}
}
d. Sa se copie elementele a doi vectori intr-un al treilea vector. Sa se ordoneze vectorul
destinatie. Sa se inverseze valorile vectorului destinatie
# region metoda 1
#endregion
#region metoda 2
Array.Sort(C);
Array.Copy(A,0,Vector_Destinatie,0,A.Length);
Array.Copy(B, 0, Vector_Destinatie, A.Length, B.Length);
#endregion
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Gestiune.Clase
{
class Angajat
{
#region campuri
#endregion
#region constructori
public Angajat()
{
_salariu = 800;
_datanasterii = "01.01.1990";
_dataangajarii = "01.01.1990";
}
#endregion
#region proprietati
#endregion
#region interfata_clasei
#endregion
}
}
namespace Gestiune
{
class Program
{
static void Main(string[] args)
{
#endregion
#endregion
#region afişare_date_angajaţi
#endregion
#region contruire_lista_angajati
case 1:
listaAngajati_2[i] = angajat2;
break;
case 2:
listaAngajati_2[i] = angajat3;
break;
case 3:
listaAngajati_2[i] = angajat4;
break;
case 4:
listaAngajati_2[i] = angajat5;
break;
}
}
#endregion
//utilizand foreach
foreach (Angajat ang in listaAngajati)
{
Console.WriteLine("Detaliile angajatului: " +
ang.DetaliiCompleteAngajat(ang));
Console.WriteLine();
}
//utilizand for
for (int i = 0; i < listaAngajati.Count; i++)
{
//Trebuie sa realizam conversia obiectului
listaAngajati[i] in tipul Angajat
Console.WriteLine("Detaliile angajatului " +
(i+1) + " sunt: " +
((Angajat)listaAngajati[i]).DetaliiCompleteAngajat((Angajat)listaAngajati[i]))
;
Console.WriteLine();
}
#endregion
#region premierea_unui_angajat_norocos
indexAngajatNorocos =
randomAngajat.Next(listaAngajati_3.
Count);
listaAngajati_3[indexAngajatNorocos
].CresteSalariu(8);
Console.WriteLine("Angajatul norocos este: " + listaAngajati_
3[indexAngajatNorocos].Nume + " " +
listaAngajati_3[indexAngajatNorocos].Prenume + ", noul salariu fiind: " +
listaAngajati_3[indexAngajatNorocos].Salariu);
#endregion
Console.ReadLine();
}
}
}
4. Moștenire și Polimorfism
a. Să se realizeze o aplicaţie pentru gestiunea angajaţilor, clientilor si furnizorilor unei
companii (continuare exercițiu precedent)
public Companie()
{
}
#endregion
public Client()
{
}
#region interfata_clasei
class Furnizor:Companie
{
private string _datainfiintare = string.Empty;
private string _adresaWeb = string.Empty;
private string _adresaEmail = string.Empty;
public Furnizor()
{
}
#endregion
}
Console.WriteLine("******************ALTERNATIVA LA POLIMORFISM!
*********************************");
Console.WriteLine("**************** ALTERNATIVA LA POLIMORFISM!
*********************************");
f. Text file Write with format and write boolean value to a text file
try
{
FileStream aFile = new
FileStream("practice.txt",FileMode.OpenOrCreate);
StreamWriter sw = new StreamWriter(aFile);
bool truth = true;
sw.WriteLine("A");
sw.WriteLine("{0}",System.DateTime.Now.ToShortDateString());
sw.Write("A");
sw.Write("www.java2s.com",truth);
sw.Close();
}
catch(IOException e)
{
Console.WriteLine("An IO exception has been
thrown!"); Console.WriteLine(e.ToString());
Console.ReadLine();
return;
}
return;
FileInfo f = new
FileInfo(@"C:\Bar.txt");
FileStream fs = f.Create();
StreamWriter w = new
StreamWriter(fs); w.Write("Hello
World");
w.Close();
fs = f.Open(FileMode.Open, FileAccess.Read,
FileShare.None); StreamReader r = new
StreamReader(fs);
string t;
while ((t = r.ReadLine()) != null)
{
Console.WriteLine(t);
}
w.Close();
fs.Close();
f.Delete();
fin.Close();
fout.Close();
t. Deleting files
FileInfo MyFile = new
FileInfo(@"c:\Projects\Testing.txt");
MyFile.Create();
MyFile.Delete();
6. Network programming in .NET Framework
The network interface is not directly accessible in order to send and receive packets. We
need an intermediary connector to handle the programming interface to the network. A
socket represents a connector that connects an application to the network interface. In order
to send and receive data, we must call socket’s methods.
'System.Net.Sockets' namespace contains the classes needed by .NET for accessing the low-
level Winsock APIs. Network programming involves common concepts like the IP address
and port. IP address is a unique identifier of a computer on a network and port is like a gate
through which applications communicate with each other.
When the application needs to communicate with a remote computer or a device over the
network, we should know its IP address. Afterwards, a gate (Port) must be opened to that IP
and then send and receive the required data.
.NET defines two classes in the System.Net namespace to handle various types of IP address
information:
IPAddress (IPAddress newaddress = IPAddress.Parse("192.168.1.1");
IPEndPoint (represent a specific IP address/port combination. An IPEndPoint object
is used when binding sockets to local addresses, or when connecting sockets to remote
addresses.)
For creating a connection-oriented socket, separate sequences of functions must be used for
server programs and client programs:
1. Create a socket.
2. Bind the socket to a local IPEndPoint.
3. Place the socket in listen mode.
4. Accept an incoming connection on the socket.
As for the client, the first step is to create a Socket object. The Socket object can be used by
the socket Connect() method to connect the socket to a remote host:
a. The following example program creates a server that receives connection requests from
clients. The server is built with a synchronous socket, so execution of the server
application is suspended while it waits for a connection from a client. The application
receives a string from the client, displays the string on the console, and then echoes the
string back to the client. The string from the client must contain the string "<EOF>" to
signal the end of the message.
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
The following example program creates a client that connects to a server. The client is
built with a synchronous socket, so execution of the client application is suspended until
the server returns a response. The application sends a string to the server and then
displays the string returned by the server on the console.
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
The server
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;
namespace FileServer
{
class Program
{
static void Main(string[] args)
{
Server s = new Server();
s.StartServer();
}
}
The client
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace FileClient
{
class Program
{
static void Main(string[] args)
{
DirectoryInfo dir = new DirectoryInfo(@"C:\SourceFolder");
List<string> file_names = new List<string>();
file_names.Clear();
file_names = DirSearch(@"C:\SourceFolder");
{
foreach (string file in file_names)
{
Console.WriteLine("Sending file {0}", file);
Client.SendFile(file);
}
}
}
static List<string> DirSearch(string sDir)
{
List<string> file_names = new List<string>();
try
{
foreach (string f in Directory.GetFiles(sDir))
{
file_names.Add(f);
}
}
catch (System.Exception excpt)
{
Console.WriteLine(excpt.Message);
}
return file_names;
}
}
public class Client
{
public static string currentMsg = "Idle";
public static void SendFile(string fileName)
{
try
{
//block current thread for 5 seconds
Thread.Sleep(5000);
//create socket and ip endpoint
IPEndPoint ipEnd = CreateIPEndPoint("127.0.0.1:5656");
Socket clientSock = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.IP);
string filePath = "";
//encode name of the file
byte[] name_of_the_file = Encoding.ASCII.GetBytes(fileName);
//encode fileName Length
byte[] fileNameLen = BitConverter.GetBytes(name_of_the_file.Length);
//encode fileContent
byte[] fileData = File.ReadAllBytes(filePath + fileName);
// econde number of bytes in message
byte[] noBytesInMessage = BitConverter.GetBytes(fileData.Count());
//encode fileName
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] fileNameBytes = encoding.GetBytes(fileName);
// connect to server
clientSock.Connect(ipEnd);
//send fileName length
clientSock.Send(fileNameLen);
// send fileName
clientSock.Send(name_of_the_file);
// send numberofBytes in file
clientSock.Send(noBytesInMessage);
Console.WriteLine("start sending file...");
//send file data
clientSock.Send(fileData);
Console.WriteLine("File {0} was sent", fileName);
Console.WriteLine("Disconnecting...");
//close socket
clientSock.Close();
Console.WriteLine("File transferred.");
}
catch (Exception ex)
{
if (ex.Message == "No connection could be made")
currentMsg = "File Sending fail. Because server not running.";
else currentMsg = "File Sending fail." + ex.Message;
}
}
public static IPEndPoint CreateIPEndPoint(string endPoint)
{
string[] ep = endPoint.Split(':');
if (ep.Length < 2) throw new FormatException("Invalid endpoint format");
IPAddress ip;
if (ep.Length > 2)
{
if (!IPAddress.TryParse(string.Join(":", ep, 0, ep.Length - 1), out
ip))
{
throw new FormatException("Invalid ip-adress");
}
}
else
{
if (!IPAddress.TryParse(ep[0], out ip))
{
throw new FormatException("Invalid ip-adress");
}
}
int port;
if (!int.TryParse(ep[ep.Length - 1], NumberStyles.None,
NumberFormatInfo.CurrentInfo, out port))
{
throw new FormatException("Invalid port");
}
return new IPEndPoint(ip, port);
}
}
}
The TcpClient class requests data from an Internet resource using TCP. The methods and
properties of TcpClient abstract the details for creating a Socket for requesting and receiving
data using TCP. Because the connection to the remote device is represented as a stream, data
can be read and written with .NET Framework stream-handling techniques.
The TCP protocol establishes a connection with a remote endpoint and then uses that
connection to send and receive data packets. TCP is responsible for ensuring that data packets
are sent to the endpoint and assembled in the correct order when they arrive.
To establish a TCP connection, you must know the address of the network device hosting the
service you need and you must know the TCP port that the service uses to communicate. The
Internet Assigned Numbers Authority (Iana) defines port numbers for common services (see
www.iana.org/assignments/port-numbers). Services not on the Iana list can have port
numbers in the range 1,024 to 65,535.
using System;
using System.Net.Sockets;
using System.Text;
public class TcpTimeClient
{
private const int portNum = 13;
private const string hostName = "localhost";
public static int Main(String[] args)
{
try
{
TcpClient client = new TcpClient(hostName, portNum);
NetworkStream ns = client.GetStream();
byte[] bytes = new byte[1024];
int bytesRead = ns.Read(bytes, 0, bytes.Length);
Console.WriteLine(Encoding.ASCII.GetString(bytes, 0, bytesRead));
client.Close();
Console.ReadLine();
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
return 0;
}
}
Employee Server
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
public class EmployeeSrvr
{
public static void Main()
{
byte[] data = new byte[1024];
TcpListener server = new TcpListener(9050);
server.Start();
TcpClient client = server.AcceptTcpClient();
NetworkStream ns = client.GetStream();
byte[] size = new byte[2];
int recv = ns.Read(size, 0, 2);
int packsize = BitConverter.ToInt16(size, 0);
Console.WriteLine("packet size = {0}", packsize);
recv = ns.Read(data, 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];
recv = ns.Read(size, 0, 2);
packsize = BitConverter.ToInt16(size, 0);
data = new byte[packsize];
Console.WriteLine("packet size = {0}", packsize);
recv = ns.Read(data, 0, packsize);
Employee emp2 = new Employee(data);
Console.WriteLine("emp2.EmployeeID = {0}", emp2.EmployeeID);
Console.WriteLine("emp2.LastName = {0}", emp2.LastName);
Console.WriteLine("emp2.FirstName = {0}", emp2.FirstName);
Console.WriteLine("emp2.YearsService = {0}", emp2.YearsService);
Console.WriteLine("emp2.Salary = {0}", emp2.Salary);
ns.Close();
client.Close();
server.Stop();
Console.ReadLine();
}
}
public class Employee
{
public int EmployeeID;
private int LastNameSize;
public string LastName;
private int FirstNameSize;
public string FirstName;
public int YearsService;
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;
YearsService = BitConverter.ToInt32(data, place);
place += 4;
Salary = BitConverter.ToDouble(data, place);
}
public byte[] GetBytes()
{
byte[] data = new byte[1024];
int place = 0;
Buffer.BlockCopy(BitConverter.GetBytes(EmployeeID), 0, data, place, 4);
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(YearsService), 0, data, place, 4);
place += 4;
Buffer.BlockCopy(BitConverter.GetBytes(Salary), 0, data, place, 8);
place += 8;
size = place;
return data;
}
}
Employee Client
using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
namespace ConsoleApplication1
{
class Program
{
public static Hashtable clientsList = new Hashtable();
static void Main(string[] args)
{
TcpListener serverSocket = new TcpListener(8888);
TcpClient clientSocket = default(TcpClient);
int counter = 0;
serverSocket.Start();
Console.WriteLine("Chat Server Started ....");
counter = 0;
while ((true))
{
counter += 1;
clientSocket = serverSocket.AcceptTcpClient();
byte[] bytesFrom = new byte[65536];
string dataFromClient = null;
NetworkStream networkStream = clientSocket.GetStream();
networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
dataFromClient = Encoding.Default.GetString(bytesFrom);
dataFromClient = dataFromClient.Substring(0,
dataFromClient.IndexOf("$"));
clientsList.Add(dataFromClient, clientSocket);
broadcast(dataFromClient + " Joined ", dataFromClient, false);
Console.WriteLine(dataFromClient + " Joined chat room ");
handleClient client = new handleClient();
client.startClient(clientSocket, dataFromClient, clientsList);
}
}
public static void broadcast(string msg, string uName, bool flag)
{
foreach (DictionaryEntry Item in clientsList)
{
TcpClient broadcastSocket;
broadcastSocket = (TcpClient)Item.Value;
NetworkStream broadcastStream = broadcastSocket.GetStream();
Byte[] broadcastBytes = null;
if (flag == true)
{
broadcastBytes = Encoding.ASCII.GetBytes(uName + " says : " +
msg);
}
else
{
broadcastBytes = Encoding.ASCII.GetBytes(msg);
}
broadcastStream.Write(broadcastBytes, 0, broadcastBytes.Length);
broadcastStream.Flush();
}
} //end broadcast function
}//end Main class
public class handleClient
{
TcpClient clientSocket;
string clNo;
Hashtable clientsList;
public void startClient(TcpClient inClientSocket, string clineNo, Hashtable
cList)
{
this.clientSocket = inClientSocket;
this.clNo = clineNo;
this.clientsList = cList;
Thread ctThread = new Thread(doChat);
ctThread.Start();
}
private void doChat()
{
int requestCount = 0;
byte[] bytesFrom = new byte[65536];
string dataFromClient = null;
Byte[] sendBytes = null;
string serverResponse = null;
string rCount = null;
requestCount = 0;
while ((true))
{
try
{
requestCount = requestCount + 1;
NetworkStream networkStream = clientSocket.GetStream();
networkStream.Read(bytesFrom, 0,
(int)clientSocket.ReceiveBufferSize);
dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
dataFromClient = dataFromClient.Substring(0,
dataFromClient.IndexOf("$"));
Console.WriteLine("From client - " + clNo + " : " +
dataFromClient);
rCount = Convert.ToString(requestCount);
Program.broadcast(dataFromClient, clNo, true);
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
}
}//end while
}//end doChat
} //end class handleClinet
}//end namespace
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ClientChat
{
public partial class Form1 : Form
{
TcpClient clientSocket = new TcpClient();
NetworkStream serverStream = default(NetworkStream);
string readData = null;
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox1.Text +
"$");
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
}
private void button1_Click(object sender, EventArgs e)
{
readData = "Conected to Chat Server ...";
msg();
clientSocket.Connect("127.0.0.1", 8888);
serverStream = clientSocket.GetStream();
byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox3.Text +
"$");
string x = Encoding.Default.GetString(outStream);
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
Thread ctThread = new Thread(getMessage);
ctThread.Start();
}
private void getMessage()
{
while (true)
{
serverStream = clientSocket.GetStream();
int buffSize = 0;
byte[] inStream = new byte[65536];
buffSize = clientSocket.ReceiveBufferSize;
serverStream.Read(inStream, 0, buffSize);
string returndata = Encoding.ASCII.GetString(inStream);
readData = "" + returndata;
msg();
}
}
private void msg()
{
if (this.InvokeRequired)
this.Invoke(new MethodInvoker(msg));
else
textBox2.Text = textBox2.Text + Environment.NewLine + " >> " +
readData;
}
}
}
context.Response.ContentType = "text/html";
context.Response.ContentEncoding = Encoding.UTF8;
using (var sw = new StreamWriter(context.Response.OutputStream))
{
sw.WriteLine("<html>");
sw.WriteLine("<head><meta http-equiv=\"Content-Type\" content=\"text/html;
charset=utf-8\"></head>");
sw.WriteLine("<body><ul>");
sw.WriteLine("</ul></body></html>");
}
context.Response.OutputStream.Close();
}
private static void returnFile(HttpListenerContext context, string filePath)
{
context.Response.ContentType = getcontentType(Path.GetExtension(filePath));
var buffer = new byte[bufferSize];
using (var fs = File.OpenRead(filePath))
{
context.Response.ContentLength64 = fs.Length;
int read;
while ((read = fs.Read(buffer, 0, buffer.Length)) > 0)
context.Response.OutputStream.Write(buffer, 0, read);
}
context.Response.OutputStream.Close();
}
private static void return404(HttpListenerContext context)
{
context.Response.StatusCode = 404;
context.Response.Close();
}
private static string tuneUrl(string url)
{
url = url.Replace('/', '\\');
url = HttpUtility.UrlDecode(url, Encoding.UTF8);
url = url.Substring(1);
return url;
}
private static string getcontentType(string extension)
{
switch (extension)
{
case ".avi": return "video/x-msvideo";
case ".css": return "text/css";
case ".doc": return "application/msword";
case ".gif": return "image/gif";
case ".htm":
case ".html": return "text/html";
case ".jpg":
case ".jpeg": return "image/jpeg";
case ".js": return "application/x-javascript";
case ".mp3": return "audio/mpeg";
case ".png": return "image/png";
case ".pdf": return "application/pdf";
case ".ppt": return "application/vnd.ms-powerpoint";
case ".zip": return "application/zip";
case ".txt": return "text/plain";
default: return "application/octet-stream";
}
}
}
Thread.Sleep( 5000 );
IPEndPoint ipEnd = CreateIPEndPoint( "10.163.142.181:5656" );
Socket clientSock = new Socket( AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.IP );
string filePath = "";
int port;
if (!int.TryParse( ep[ep.Length -
}
Utilizarea clientului in programul principal:
while (true) {
file_names.Clear();
file_names = DirSearch( @"C:\Napa\Inbox" );
}
}
}
static List<string> DirSearch( string sDir ) {
List<string> file_names = new
List<string>(); try {
foreach (string d in
Directory.GetDirectories( sDir )) { foreach
(string f in Directory.GetFiles( d )) {
file_names.Add( f );
}
DirSearch( d );
}
} catch (System.Exception excpt) {
Console.WriteLine( excpt.Message
);
}
return file_names;
}
Implementare Server
public Server() {
IPAddress sIp = IPAddress.Parse(
"10.162.0.94" ); ipEnd = new IPEndPoint( sIp,
5656 ); tcpListener = new
TcpListener( 5656 );
sock = new Socket( AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.IP
);
sock.Bind( ipEnd );
}