简体   繁体   English

ServerSocket.accept()

[英]ServerSocket.accept()

While i am running my program i have svrSocket.accept() method..My program is automatically getting terminated when it reaches to svrSocket.accept() method. 当我运行程序时,我有svrSocket.accept()方法。.当我的程序到达svrSocket.accept()方法时,它会自动终止。 Please suggest what needs to be done. 请提出需要做什么。

Without example code or an error message for reference, according to the API , your application may not be catching one of the following exceptions: 根据API的规定 ,如果没有示例代码或错误消息供参考,则您的应用程序可能无法捕获以下异常之一:

  1. IOException IOException
  2. SecurityException SecurityException
  3. SocketTimeoutException SocketTimeoutException
  4. IllegalBlockingModeException IllegalBlockingModeException

Also, are you sure your application terminates? 另外,您确定您的应用程序会终止吗? The only reason I ask is accept() blocks until a connection is made. 我问的唯一原因是accept()阻塞直到建立连接。

Here is what you need to provide before we can really help you. 这是您需要提供的,我们才能真正为您提供帮助。

  1. Stacktraces for exceptions that accept() might be throwing. 可能引发异常的stacktraces。 If this is a simple console application look for those in the console of your IDE. 如果这是一个简单的控制台应用程序,请在IDE的控制台中查找。 There is a separate window that it runs in and shows output like this. 它在其中运行一个单独的窗口,并显示如下输出。

  2. Is the program truly terminating? 该程序真的终止了吗? accept() is a blocking call and blocks forever until another process connects to it through the socket. accept()是一个阻塞调用,并且永远阻塞,直到另一个进程通过套接字连接到它为止。 Have you tried running a client that connects to your server socket to see if it un blocks and continues to run? 您是否尝试过运行连接到服务器套接字的客户端以查看它是否解除阻止并继续运行? If you have to click the stop button, if multiple run windows are open then your program is simply blocked on the accept() call and it's working as designed. 如果必须单击停止按钮,并且打开了多个运行窗口,则您的程序仅在accept()调用时被阻止,并且程序按设计运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM