Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8051197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:15:03+00:00 2026-06-05T07:15:03+00:00

I put together a simple socket server (see below). Currently, it is not capable

  • 0

I put together a simple socket server (see below). Currently, it is not capable of handling multiple/concurrent requests. How can I make the socket server more efficient — i.e. capable of handling concurrent requests? Are there any clojure constructs I can leverage? Thus far, I’ve thought of using either java’s NIO (instead of IO) or netty (as pointed out here).

(ns server.policy
    (:import 
        (java.net ServerSocket SocketException)
        java.io.PrintWriter))

    (defn create-socket
        "Creates a socket on given port."
        [port]
        (ServerSocket. port))

    (defn get-writer
        "Create a socket file writer."
        [client]
        (PrintWriter. (.getOutputStream client)))

    (defn listen-and-respond
        "Accepts connection and responds."
        [server-socket service]
        (let [client (.accept server-socket)
              socket-writer (get-writer client)]
            (service socket-writer)))

    (defn policy-provider
        "Returns domain policy content."
        [socket-writer]
        (.print socket-writer "<content>This is a test</content>")
        (.flush socket-writer)
        (.close socket-writer))

    (defn run-server
        [port]
        (let [server-socket (create-socket port)]
            (while (not (.isClosed server-socket))
                (listen-and-respond server-socket policy-provider))))
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T07:15:04+00:00Added an answer on June 5, 2026 at 7:15 am

    I have had success using Netty directly. However, if you want something that feels a little more like idiomatic Clojure code, take a look at the aleph library. It uses Netty internally, but results in much more simple code:

    (use 'lamina.core 'aleph.tcp)
    
    (defn echo-handler [channel client-info]
      (siphon channel channel))
    
    (start-tcp-server echo-handler {:port 1234})
    

    Also, keep in mind that sometimes you need to reference the lamina documentation in addition to the aleph documentation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to put together simple TCP server using Python and Twisted. The server
I've put together a pretty simple competition script - it's commented out below and
This simple Python method I put together just checks to see if Tomcat is
I've put together a small code-sample below (Currently in C# 3.5 but would also
I put together a simple system so that my dad can manage a website
As you can tell I'm trying to put together a very simple 3d engine.
I've put together a simple form to highlight the concepts of dynamic forms. What
I'm trying to put together a simple RSS widget (for my wordpress blog) that
Put together an extremely simple Knockout.js exmaple to learn how it works. I immediately
I put together a simple script that pulls the product name, category name and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.