Created
April 22, 2023 09:05
-
-
Save nkalra0123/cffcf7d3363082b18ac8d5fc038128b9 to your computer and use it in GitHub Desktop.
TCP server in java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Override | |
public void run() { | |
try { | |
httpd.getMyServerSocket().bind(httpd.hostname != null ? new InetSocketAddress(httpd.hostname, httpd.myPort) : new InetSocketAddress(httpd.myPort)); | |
hasBinded = true; | |
} catch (IOException e) { | |
this.bindException = e; | |
return; | |
} | |
do { | |
try { | |
final Socket finalAccept = httpd.getMyServerSocket().accept(); | |
if (this.timeout > 0) { | |
finalAccept.setSoTimeout(this.timeout); | |
} | |
final InputStream inputStream = finalAccept.getInputStream(); | |
httpd.asyncRunner.exec(httpd.createClientHandler(finalAccept, inputStream)); | |
} catch (IOException e) { | |
NanoHTTPD.LOG.log(Level.FINE, "Communication with the client broken", e); | |
} | |
} while (!httpd.getMyServerSocket().isClosed()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment