hi everyone can someone explain me the code under ...
it's a Client - Server code .. so im not undestading when i comunicate with the server .. can you explain this code what is does and other stuff...
}
}
//Metoda per dergim te te dhenave te serveri
public bool Send(char tipi, byte[] buffer)
{
try
{
if (m_tcpClient.Connected)
{
byte[] tipiBuffer = BitConverter.GetBytes(tipi);
byte[] sendBuffer = new byte[buffer.Length + 2];
tipiBuffer.CopyTo(sendBuffer, 0);
buffer.CopyTo(sendBuffer, 2);
m_networkStream.Write(sendBuffer, 0, sendBuffer.Length);
}
else
{
return false;
}
}
catch (Exception ex)
{
return false;
}
return true;
}
//metoda qe e ndegjon sererin qka po kten
private void Listening()
{
try
{
while (m_tcpClient.Connected)
{
byte[] buffer = new byte[1024];
int readBytes = m_networkStream.Read(buffer, 0, buffer.Length - 1);
//Memory Stream per te ruajtur te dhenat
MemoryStream memoryStream = new MemoryStream();
memoryStream.Write(buffer, 0, readBytes);
char operations = BitConverter.ToChar(buffer, 0);
switch (operations)
{
case Komand:
string komanda = Encoding.ASCII.GetString(buffer, 2, readBytes - 2);
Console.WriteLine(Shfaq(buffer, readBytes - 2));
break;
case Data:
ShkarkoFile(buffer, readBytes);
break;
case Message:
string dataCommand = Encoding.ASCII.GetString(buffer, 2, readBytes - 2);
Console.WriteLine(ShfaqMesazhin(buffer, readBytes - 2));
break;
}
if (memoryStream != null)
memoryStream.Close();
}
}
catch (Exception ex)
{
}
}
private string Shfaq(byte[] buffer, int length)
{
return Encoding.ASCII.GetString(buffer, 2, length);
}
private string ShfaqMesazhin(byte[] buffer, int length)
{
return Encoding.ASCII.GetString(buffer, 2, length);
}
//e ruajme file-in qe na kteet prej sererit nese ekziston
private void ShkarkoFile(byte[] receivedDataBuffer, int readBytes)
{
FileStream fileStream = new FileStream(m_clientPath + @"\" + m_shkarkoFileName, FileMode.Create, FileAccess.Write);
fileStream.Write(receivedDataBuffer, 2, readBytes - 2);
fileStream.Close();
}
private bool NgarkoFile(string fileName)
{
bool check = false;
if (File.Exists(m_clientPath + @"\" + fileName))
{
FileStream fileStream = new FileStream(m_clientPath + @"\" + fileName, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[fileStream.Length];
fileStream.Read(buffer, 0, buffer.Length);
Send(Data, buffer);
fileStream.Close();
check = true;
}
return check;
}
}
}
Loading

VulpesRank #55 · 29.2K reputationPosted Jan 5, 2012, 9:50 AM EST
* The memory stream is then closed.
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 4, 2012, 7:07 PM EST
Are you use web application?
if yes then its a server side code.
in web application only java script code run on client, other code run on server.
hope this help.
jimy arsenal8 reputationPosted Jan 5, 2012, 2:15 AM EST
Jignesh TrivediRank #16 · 50.3K reputationPosted Jan 5, 2012, 3:04 AM EST
for console and window base application all are client code and run on client side.
so as per me this all are client code.
hope this help.
jimy arsenal8 reputationPosted Jan 5, 2012, 7:40 AM EST
private void Listening()
{
try
{
while (m_tcpClient.Connected)
{
byte[] buffer = new byte[1024];
int readBytes = m_networkStream.Read(buffer, 0, buffer.Length - 1);
//Memory Stream per te ruajtur te dhenat
MemoryStream memoryStream = new MemoryStream();
memoryStream.Write(buffer, 0, readBytes);
char operations = BitConverter.ToChar(buffer, 0);
switch (operations)
{
case Komand:
string komanda = Encoding.ASCII.GetString(buffer, 2, readBytes - 2);
Console.WriteLine(Shfaq(buffer, readBytes - 2));
break;
case Data:
ShkarkoFile(buffer, readBytes);
break;
little explaining ..it will be very helpful
jimy arsenal8 reputationPosted Jan 5, 2012, 12:39 PM EST
why buffer.length - 1 ? it's because it's using Array ?..thankyou again
VulpesRank #55 · 29.2K reputationPosted Jan 5, 2012, 1:57 PM EST