我不知道为什么会这样? 当我扫描少于300个TCP端口时,我没有发生? 当我需要扫描多个端口时它会崩溃应用程序?任何人都有任何想法来解决这个错误?我花了几天时间:)
public void start(int threadCounter)
{
for (int i = 0; i < threadCounter; i++)
{
Thread thread1 = new Thread(new ThreadStart(RunScanTcp));
thread1.Name = "Thread : " + i.ToString();
thread1.IsBackground = true;
thread1.Start();
}
}
public void RunScanTcp()
{
int port;
var reset3 = new TaskCompletionSource<bool>();
//while there are more ports to scan
while ((port = portList.NextPort()) != -1)
{
var reset2 = new TaskCompletionSource<bool>();
Activity.RunOnUiThread(() =>
{
tcp_count = tcp_count + 1;
});
Thread.Sleep(100);
count = port;
Console.WriteLine("Current Port Count : " + count.ToString());
try
{
Connect(host, port, tcpTimeout);
}
catch
{
continue;
}
Activity.RunOnUiThread(() =>
{
received_tcp = received_tcp + 1;
mdata.Add(new data() { titulli = "Port : " + port, sekuenca = "Sequence : ", ttl = "Connection Sucessfull !", madhesia = "", koha = "Time : " });
mAdapter.NotifyItemInserted(mdata.Count() - 1);
if (ndaluar == false)
{
mRecyclerView.ScrollToPosition(mdata.Count() - 1);
}
reset2.TrySetResult(true);
});
reset2.Task.Wait();
Console.WriteLine("TCP Port {0} is open ", port);
}
if (turnOff == true)
{
turnOff = false;
Activity.RunOnUiThread(() =>
{
mdata.Add(new data() { titulli = "General Information", sekuenca = "Transmited : " + tcp_count + ",", ttl = "Open Ports : " + received_tcp + ",", madhesia = "Closed Ports : " + (tcp_count - received_tcp), koha = "" });
mAdapter.NotifyItemInserted(mdata.Count());
if (ndaluar == false)
{
mRecyclerView.ScrollToPosition(mdata.Count() - 1);
}
ping_progress.Visibility = ViewStates.Invisible;
dergo_ping.Text = "Scan";
reset3.TrySetResult(true);
});
reset3.Task.Wait();
Console.WriteLine("Scan Complete !!!");
}
}
public TcpClient Connect(string hostName, int port, int timeout)
{
var newClient = new TcpClient();
var state = new isTcpPortOpen
{
MainClient = newClient,
tcpOpen = true
};
IAsyncResult ar = newClient.BeginConnect(hostName, port, AsyncCallback, state);
state.tcpOpen = ar.AsyncWaitHandle.WaitOne(timeout, false);
if (state.tcpOpen == false || newClient.Connected == false)
{
throw new Exception();
}
return newClient;
}
public void AsyncCallback(IAsyncResult asyncResult)
{
var state = (isTcpPortOpen)asyncResult.AsyncState;
TcpClient client = state.MainClient;
try
{
client.EndConnect(asyncResult);
}
catch
{
return;
}
if (client.Connected && state.tcpOpen)
{
return;
}
client.Close();
}
这是调试输出
rt Count : 961
05-17 23:08:29.430 I/mono-stdout(13704): Current Port Count : 961
Current Port Count : 962
05-17 23:08:29.449 I/mono-stdout(13704): Current Port Count : 962
Current Port Count : 963
05-17 23:08:29.451 I/mono-stdout(13704): Current Port Count : 963
Current Port Count : 964
05-17 23:08:29.462 I/mono-stdout(13704): Current Port Count : 964
05-17 23:08:29.464 E/Parcel (13704): dup() failed in Parcel::read, i is 0, fds[i] is -1, fd_count is 1, error: Too many open files
Current Port Count : 965
05-17 23:08:29.481 I/mono-stdout(13704): Current Port Count : 965
05-17 23:08:29.483 E/Parcel (13704): dup() failed in Parcel::read, i is 0, fds[i] is -1, fd_count is 1, error: Too many open files
05-17 23:08:29.488 E/Parcel (13704): writeDupFileDescriptor: error 24 dup fd 1017
05-17 23:08:29.489 E/Surface (13704): queueBuffer: error queuing buffer to SurfaceTexture, -22
05-17 23:08:29.489 E/EGL-ERROR: void __egl_platform_queue_buffer_android(mali_base_ctx_handle, egl_buffer*):1374: unable to queue buffer (0x0xb8ed1380)
05-17 23:08:29.500 E/Parcel (13704): dup() failed in Parcel::read, i is 0, fds[i] is -1, fd_count is 1, error: Too many open files
Current Port Count : 966
05-17 23:08:29.500 I/mono-stdout(13704): Current Port Count : 966
Current Port Count : 967
Current Port Count : 968
05-17 23:08:29.515 I/mono-stdout(13704): Current Port Count : 967
05-17 23:08:29.516 I/mono-stdout(13704): Current Port Count : 968
05-17 23:08:29.519 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -2147483646, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.520 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -2147483646, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.520 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
Current Port Count : 969
05-17 23:08:29.524 I/mono-stdout(13704): Current Port Count : 969
Current Port Count : 969
05-17 23:08:29.524 I/mono-stdout(13704): Current Port Count : 969
Current Port Count : 970
05-17 23:08:29.534 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.535 I/mono-stdout(13704): Current Port Count : 970
05-17 23:08:29.535 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.536 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:29.552 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.553 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.553 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
Current Port Count : 972
05-17 23:08:29.556 I/mono-stdout(13704): Current Port Count : 972
Current Port Count : 971
05-17 23:08:29.556 I/mono-stdout(13704): Current Port Count : 971
Current Port Count : 973
05-17 23:08:29.568 I/mono-stdout(13704): Current Port Count : 973
05-17 23:08:29.571 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.571 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.572 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
Current Port Count : 974
05-17 23:08:29.586 I/mono-stdout(13704): Current Port Count : 974
Current Port Count : 975
Current Port Count : 976
Current Port Count : 977
Current Port Count : 979
Current Port Count : 978
Current Port Count : 980
05-17 23:08:29.589 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.589 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.590 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:29.605 I/mono-stdout(13704): Current Port Count : 975
05-17 23:08:29.605 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.606 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.607 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:29.622 I/mono-stdout(13704): Current Port Count : 976
05-17 23:08:29.622 I/mono-stdout(13704): Current Port Count : 977
05-17 23:08:29.624 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.625 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.625 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:29.626 I/mono-stdout(13704): Current Port Count : 979
05-17 23:08:29.626 I/mono-stdout(13704): Current Port Count : 978
05-17 23:08:29.637 I/mono-stdout(13704): Current Port Count : 980
05-17 23:08:29.642 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.643 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.643 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
Current Port Count : 981
05-17 23:08:29.658 I/mono-stdout(13704): Current Port Count : 981
05-17 23:08:29.659 I/mono-stdout(13704): Current Port Count : 982
05-17 23:08:29.661 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.662 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.662 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
Current Port Count : 982
Current Port Count : 983
05-17 23:08:29.670 I/mono-stdout(13704): Current Port Count : 983
05-17 23:08:29.677 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.678 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.679 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
Current Port Count : 984
05-17 23:08:29.688 I/mono-stdout(13704): Current Port Count : 984
05-17 23:08:29.696 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.696 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.697 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
Current Port Count : 985
05-17 23:08:29.707 I/mono-stdout(13704): Current Port Count : 985
05-17 23:08:29.714 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.715 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.715 I/System (13704): FinalizerDaemon: finalize objects = 615
05-17 23:08:29.715 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
Current Port Count : 986
Current Port Count : 987
05-17 23:08:29.723 I/mono-stdout(13704): Current Port Count : 986
05-17 23:08:29.724 I/mono-stdout(13704): Current Port Count : 987
Current Port Count : 988
Current Port Count : 989
05-17 23:08:29.728 I/mono-stdout(13704): Current Port Count : 988
05-17 23:08:29.728 I/mono-stdout(13704): Current Port Count : 989
05-17 23:08:29.731 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.732 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.732 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
Current Port Count : 990
05-17 23:08:29.739 I/mono-stdout(13704): Current Port Count : 990
Thread finished: Thread : 4 #11
Current Port Count : 991
Current Port Count : 992
05-17 23:08:29.747 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.748 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:29.748 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:29.760 I/mono-stdout(13704): Current Port Count : 991
05-17 23:08:29.764 I/mono-stdout(13704): Current Port Count : 992
Current Port Count : 1000
Current Port Count : 1000
05-17 23:08:29.970 I/mono-stdout(13704): Current Port Count : 1000
05-17 23:08:29.970 I/mono-stdout(13704): Current Port Count : 1000
05-17 23:08:29.971 I/mono-stdout(13704): Current Port Count : 1000
Thread finished: Thread : 5 #12
Current Port Count : 1000
Current Port Count : 1000
05-17 23:08:29.985 I/mono-stdout(13704): Current Port Count : 1000
05-17 23:08:29.985 I/mono-stdout(13704): Current Port Count : 1000
Thread finished: Thread : 8 #15
Thread finished: Thread : 1 #8
Current Port Count : 1000
05-17 23:08:30.015 I/mono-stdout(13704): Current Port Count : 1000
Thread finished: Thread : 3 #10
Current Port Count : 1000
Thread finished: Thread : 2 #9
Current Port Count : 1000
05-17 23:08:30.041 I/mono-stdout(13704): Current Port Count : 1000
Thread finished: Thread : 0 #7
Current Port Count : 1000
05-17 23:08:30.073 I/mono-stdout(13704): Current Port Count : 1000
Thread finished: Thread : 7 #14
Thread finished: Thread : 6 #13
Scan Complete !!!
05-17 23:08:30.099 I/mono-stdout(13704): Scan Complete !!!
Thread finished: Thread : 9 #16
The thread 'Unknown' (0xb) has exited with code 0 (0x0).
The thread 'Unknown' (0xc) has exited with code 0 (0x0).
The thread 'Thread : 8' (0xf) has exited with code 0 (0x0).
The thread 'Thread : 1' (0x8) has exited with code 0 (0x0).
The thread 'Thread : 3' (0xa) has exited with code 0 (0x0).
The thread 'Unknown' (0x9) has exited with code 0 (0x0).
The thread 'Unknown' (0x7) has exited with code 0 (0x0).
The thread 'Unknown' (0xe) has exited with code 0 (0x0).
The thread 'Unknown' (0xd) has exited with code 0 (0x0).
The thread 'Unknown' (0x10) has exited with code 0 (0x0).
05-17 23:08:30.159 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.160 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.161 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:30.166 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.167 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.167 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:30.176 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.176 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.177 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:30.193 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.194 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.194 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:30.211 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.211 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.212 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:30.228 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.229 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.230 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:30.246 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.247 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.247 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:30.264 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.264 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
05-17 23:08:30.265 E/OpenGLRenderer(13704): GL error: GL_INVALID_VALUE
05-17 23:08:30.282 E/EGL-ERROR: void __egl_platform_dequeue_buffer(egl_surface*):1737: failed to dequeue buffer from native window 0xb8f95410; err = -38, buf = 0x0,max_allowed_dequeued_buffers 3
答案 0 :(得分:2)
使用后需要Dispose
TcpClient
。