简体   繁体   中英

Socket never stop searching for SocketServer

Ok so my question is really simple as I have it I pretty much have a server and a client program, however I don't want my server to have to be on for client to run, so I want to have it so the client never stops searching for server and all I have to do is turn server on, does anyone know how I'd do that? thanks

Put it in a while loop. Keep in mind that this will stall your program until it connects, so you should probably do this on a separate thread.

boolean done = false;
while (!done) {
    try {
        // Socket initialization code
    } catch (IOException e) {
        if (!e.getMessage().equals(/* Error code for unable to find server */) {
            done = true;
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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