Ich habe eine Konsole-Anwendung, die darauf wartet, dass der Client angegebenen Socket angeschlossen wird, nachdem Client akzeptiert, beginnt Daten zu füttern, wenn nach einer Weile Client-Anwendung stoppt, Vertreiber selbst verlassen, aber ich würde Verteiler nur ändern mode in listen for client, wenn die Verbindung zum Client unterbrochen wird, startet der Distributor nur zum Warten, aber er beendet sich.Socket Feeder Exits
static class Program
{
static void Main()
{
Start()
}
}
private void Start()
{
WaitForClientConnection();
//waits till client connect
StartReceive();
}
private void WaitForClientConnection()
{
_tcpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_tcpSocket.Bind(new IPEndPoint(IPAddress.Parse("172.16.192.40"), 7000));
_tcpSocket.Listen(100);
_tcpClientAcceptSocket = _tcpSocket.Accept();
}
public void StartReceive()
{
try
{
Console.WriteLine("Starting to receive data...");
while (_tcpClient.Connected)
{
//sendind data to client
}
if (!_tcpClient.Connected)
{
// if client socket listener is stops somehow, I also close _tcpClient connection after that start to keep waiting for clients
Console.WriteLine("Closing the connection...");
_tcpClient.Close();
//here start(), and WaitForClientConnection() are begin again(I realized and sure) however in WaitForClientConnection() function exits itself from application not wait for client
Start();
}
}
}
Was könnte das Problem sein?
dank