You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ignite.apache.org by Vladislav Pyatkov <vl...@gmail.com> on 2016/09/06 12:19:47 UTC

Re: question about TcpServer inside ServerImpl.java

Hi,

This code finds first port from range, which do not busy.

This may be helpful, if you use some instance of server with same
configuration in one physical machine, in that case you will not know,
which a port from range have not busy yet.

On Tue, Sep 6, 2016 at 3:01 PM, Zhengqingzheng <zh...@huawei.com>
wrote:

> Hi there,
>
> I am reading the socket communication part of the ignite source code. And
> I have a question regards to the socket server.
>
> Inside the ServerImpl.java, there is a private class called TcpServer
> which will start a socket on selected port.
>
> If portRange is used, which means Tcp Socket should listened on several
> ports, like [ 47500, 47501,…47509] .
>
> But According the codes, it seems that only one port is opened for
> listening?
>
> And I guess this is why lots of socket closed exception occurs.
>
>
>
>
>
> Please see the source code with red font for the highlights
>
>
>
> *private* *class* TcpServer *extends* IgniteSpiThread {
>
>         /** Socket TCP server listens to. */
>
>         *private* ServerSocket srvrSock;
>
>
>
>         /** Port to listen. */
>
>         *private* *int* port;
>
>
>
>         /**
>
>          * Constructor.
>
>          *
>
>          * *@throws* IgniteSpiException In case of error.
>
>          */
>
>         TcpServer() *throws* IgniteSpiException {
>
>             *super*(spi.ignite().name(), "tcp-disco-srvr", log);
>
>
>
>             setPriority(spi.threadPri);
>
>
>
>             *int* *lastPort* = spi.locPortRange == 0 ? spi.locPort : spi.
> locPort + spi.locPortRange - 1;
>
>
>
>            * for (port = spi.locPort; port <= lastPort; port++)* {
>
>                 *try* {
>
>                     *if* (spi.isSslEnabled())
>
>                         srvrSock = spi.sslSrvSockFactory.
> createServerSocket(port, 0, spi.locHost);
>
>                     *else*
>
>                         srvrSock = *new* ServerSocket(port, 0, spi.locHost
> );
>
>
>
>                     *if* (log.isInfoEnabled())
>
>                         log.info("Successfully bound to TCP port [port="
> + port + ", localHost=" + spi.locHost + ']');
>
>
>
>                     *return**; // if lastPort is defined as the
> portRange+ locPort, *
>
> *                        // why "return" is used in here? *
>
> *                        // shouldn't keep running until for loop finish? *
>
>                 }
>
>                 *catch* (IOException e) {
>
>                     *if* (log.isDebugEnabled())
>
>                         log.debug("Failed to bind to local port (will try
> next port within range) " +
>
>                             "[port=" + port + ", localHost=" + spi.locHost
> + ']');
>
>
>
>                     onException("Failed to bind to local port. " +
>
>                         "[port=" + port + ", localHost=" + spi.locHost +
> ']', e);
>
>                 }
>
>             }
>
>
>
>
>
> Best Regards,
>
> Kevin
>



-- 
Vladislav Pyatkov