Giter VIP home page Giter VIP logo

basictcp_java's Introduction

Documentation

TCPServer is a simple TCP server implemented in Java. It accepts client connections and responds with a basic "Hello World" message using the HTTP protocol.

Features

  • Utilizes a fixed thread pool to handle multiple client connections concurrently.
  • Uses the standard Java logging framework for logging events and errors.
  • Implements resource management to ensure proper closure of sockets and streams.

Usage

  1. Compile the TCPServer.java file:

    javac TCPServer.java
  2. Run the compiled Java class:

    java TCPServer
  3. The server starts and listens on port 8080. You can connect to it using a web browser or tools like curl:

    curl http://localhost:8080

Configuration

  • PORT: The port on which the server listens. Currently set to 8080.
  • THREAD_POOL: A fixed-size thread pool executor used for handling client connections. The size is currently set to 5.

Methods

main(String[] args)

The main method initializes the server socket and starts listening for client connections. For each client connection, it dispatches the processing task to the thread pool.

processClientConnection(Socket clientSocket)

Handles the client connection. It writes a basic HTTP response with the "Hello World" message to the connected client.

  • Parameters:

    • clientSocket: The socket representing the client connection.
  • Behavior:

    • Writes an HTTP response with "Hello World" content.

Error Handling

Errors and exceptions are logged using the standard Java logging framework. Specific catch blocks are provided for IOException and general exceptions to ensure meaningful error messages.

Dependencies

  • Java Standard Library

basictcp_java's People

Contributors

rupysdxe avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.