Moje pitanje je kako da unutar te petlje ispitam da li se klijentska aplikacija otkačila, da bih se mogao vratiti na čekanje nove konekcije sa klijenta (client = socket.Accept())
Code:
public void Listen()
{
IPEndPoint ip = new IPEndPoint(IPAddress.Any, 9999);
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
string komanda = "";
Console.WriteLine(ip);
Console.WriteLine(socket.Blocking);
Console.WriteLine(socket.IsBound);
socket.Bind(ip);
socket.Listen(10);
Console.WriteLine("Waiting for a client...");
while (true)
{
con = false;
try
{
client = socket.Accept();
}
catch (ObjectDisposedException ods)
{
break;
}
catch (SocketException se)
{
break;
}
con = true;
try
{
clientep = (IPEndPoint)client.RemoteEndPoint;
Console.WriteLine("Connected with {0} at port {1}", clientep.Address, clientep.Port);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
byte[] data = new byte[1024];
while (con)
{
try
{
data = new byte[1024];
int receivedDataLength = client.Receive(data);
while (true) // ********************
{
komanda += Encoding.ASCII.GetString(data, 0, receivedDataLength);
if (komanda.IndexOf("#") > -1)
break;
data = new byte[1024];
receivedDataLength = client.Receive(data);
}
if ((komanda.Length > 0) && (komanda.IndexOf("send") > -1))
{
komanda = MainClass.RWfile("R", "");
}
komanda = "";
if (uspori)
Thread.Sleep(100);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
con = false;
}
}
if (open == false)
break;
}
//Console.WriteLine("Disconnected from {0}", clientep.Address);
//client.Close();
//socket.Close();
}
public void Listen()
{
IPEndPoint ip = new IPEndPoint(IPAddress.Any, 9999);
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
string komanda = "";
Console.WriteLine(ip);
Console.WriteLine(socket.Blocking);
Console.WriteLine(socket.IsBound);
socket.Bind(ip);
socket.Listen(10);
Console.WriteLine("Waiting for a client...");
while (true)
{
con = false;
try
{
client = socket.Accept();
}
catch (ObjectDisposedException ods)
{
break;
}
catch (SocketException se)
{
break;
}
con = true;
try
{
clientep = (IPEndPoint)client.RemoteEndPoint;
Console.WriteLine("Connected with {0} at port {1}", clientep.Address, clientep.Port);
}
catch(Exception ex)
{
Console.WriteLine(ex.Message);
}
byte[] data = new byte[1024];
while (con)
{
try
{
data = new byte[1024];
int receivedDataLength = client.Receive(data);
while (true) // ********************
{
komanda += Encoding.ASCII.GetString(data, 0, receivedDataLength);
if (komanda.IndexOf("#") > -1)
break;
data = new byte[1024];
receivedDataLength = client.Receive(data);
}
if ((komanda.Length > 0) && (komanda.IndexOf("send") > -1))
{
komanda = MainClass.RWfile("R", "");
}
komanda = "";
if (uspori)
Thread.Sleep(100);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
con = false;
}
}
if (open == false)
break;
}
//Console.WriteLine("Disconnected from {0}", clientep.Address);
//client.Close();
//socket.Close();
}
SELECT * FROM หน่วยงานหลัก WHERE ยสันติ LIKE 'โดย%'