Skip to content

metamorph/weekly-ten

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
doc
 
 
 
 
 
 
 
 
 
 
 
 

Weekly Challenge #10

The Weekly Programming Challenge : http://weblog.jamisbuck.org/2016/10/1/weekly-programming-challenge-10.html

Installation

Requires Leiningen to build:

lein uberjasr

Usage

To start the server:

$ java -jar target/uberjar/weekly-ten-0.1.0-SNAPSHOT-standalone.jar --server <port>

To launch a client that will send a query to the server:

$ java -jar target/uberjar/weekly-ten-0.1.0-SNAPSHOT-standalone.jar --client <host> <port> <query>

The query engine is really simple - it simply returns the query reversed.

The Phteven Variant

$ java -jar target/uberjar/weekly-ten-0.1.0-SNAPSHOT-standalone.jar --pherver <port>

This starts a server that will delegate queries to Phteven.IO :-)

Use it like so:

$ java -jar target/uberjar/weekly-ten-0.1.0-SNAPSHOT-standalone.jar --client <host> <port> "Hello, Steven"

> Querying server localhost:9999 : Hello, Steven => 
> Hello, Phteven

Design

The server is built in a way that allows a custom ‘handler’ to be defined. When launching from the command-line the simple-protocol-handler is used.

The server uses good old threads to support multiple concurrent clients.

The simple-protocol-handler defines the protocol described in the challenge.

The server can be started in embedded mode like so:

(weekly-ten.server/start-server handler-function port)

where the handler-function is a function that takes two parameters: a java.io.InputStream (for reading from the client) and a java.io.OutputStream (for writing to the client). The accepting connections, managing resources etc. is handled outside of this.

So - in theory - implementing the HTTP server should be possible by simple adding another “handler function”.

Due to lack of time I decided to skip the HTTP client/server challenge. Instead I decided to implement a simple HTTP POST client, and to implement a query-handler that send the query to Phteven.IO to get a phtevenized response :-).

Bugs

Most likely.

License

Copyright © 2016

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

Releases

No releases published

Packages

No packages published