Skip to content

A robust, flexible, and generalized java server-client API (JSC) built on top of the java socket interface and raw TCP. JSC also supports event-driven architecture for communication.

Notifications You must be signed in to change notification settings

pj-25/JavaServerClientAPI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

40 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ“¨ JavaServerClientAPI

COMMIT_STATUS

πŸ“– Jump to JavaDocs --->

πŸ“‘ Library Structure

jsc
β”œβ”€β”€ jConnection
β”‚Β Β  β”œβ”€β”€ JCloseEventConsumer.java
β”‚Β Β  β”œβ”€β”€ JConnection.java
β”‚Β Β  └── JConnectionManager.java
β”œβ”€β”€ jEventManager
β”‚Β Β  β”œβ”€β”€ JEventCode.java
β”‚Β Β  β”œβ”€β”€ JEventConsumer.java
β”‚Β Β  β”œβ”€β”€ JEventDataSender.java
β”‚Β Β  β”œβ”€β”€ JEventManager.java
β”‚Β Β  └── JEventType.java
β”œβ”€β”€ jMessageHandler
β”‚Β Β  β”œβ”€β”€ JFileConsumer.java
β”‚Β Β  β”œβ”€β”€ JMessageCode.java
β”‚Β Β  β”œβ”€β”€ JMessageConsumer.java
β”‚Β Β  β”œβ”€β”€ JMessageDelimiter.java
β”‚Β Β  β”œβ”€β”€ JMessageFormatHandler.java
β”‚Β Β  β”œβ”€β”€ JMessageSender.java
β”‚Β Β  └── JMessageType.java
β”œβ”€β”€ jObjectParser
β”‚Β Β  β”œβ”€β”€ JObjectParseException.java
β”‚Β Β  └── JObjectParser.java
└── jServer
    β”œβ”€β”€ JClientConnectionsHandler.java
    β”œβ”€β”€ JConnectionHandler.java
    β”œβ”€β”€ JRequestManager.java
    β”œβ”€β”€ JResponseSender.java
    β”œβ”€β”€ JServer.java
    └── JSocketConsumer.java

5 directories, 23 files

*click any of the above highlighted file to navigate to its source code

πŸ—οΈ JSC Architecture

  • System Design

    JSC system architecture
  • JSC Integration

    JSC system integration

🎒 Getting Started

  • Server Side:

    • Server implementation:

      • EchoServer.java
        import jsc.jServer.JServer;
        import java.io.IOException;
        
        public class EchoServer {
            public static void main(String []s){
                try{
                    JServer echoServer = new JServer(EchoJRequestManagerImpl.class);
                    echoServer.start();
                }catch (IOException e){
                    System.out.println("Unable to start server :(");
                }
            }
        }
      • EchoJRequestManagerImpl.java
        import jsc.jServer.JRequestManager;
        
        public class EchoJRequestManagerImpl extends JRequestManager {
            @Override
            public void accept(String req){    
                //write your logic here to serve the request
                
                System.out.println("Received Request: "+req);   
                write(req);
            }
        }
      • Default server port: 5656
    • Run Server:

      javac -cp JSERVER.jar EchoJRequestManagerImpl.java
      javac -cp JSERVER.jar:. EchoServer.java
      java -cp JSERVER.jar:. EchoServer
  • Client Side:

    • Client implementation:

      • TestRelayEchoClient.java
        import jsc.jConnection.JConnection;
        
        import java.io.IOException;
        import java.util.Scanner;
        
        public class TestRelayEchoClient {
        
            public static Scanner scanner = new Scanner(System.in);
            public static void main(String []s){
                try{
                    JConnection jConnection = new JConnection("127.0.0.1", 5656, (res)->{
                        //write your logic here to consume the response
                        System.out.println(res);
                    });
                    jConnection.run();
                    System.out.println("Write your message and press enter...(write \"exit\" to stop)");
                    String msg;
                    while(jConnection.isConnected()){
                        msg = scanner.nextLine();
                        if(msg.equals("exit")){
                            break;
                        }
                        jConnection.write(msg);
                    }
                    jConnection.close();
                    System.out.println("----------- Bye :) -----------");
                }catch (IOException ioE){
                    System.out.println("Server connection lost, check your network connection :(");
                }
            }
        
        }
      • Output:
        Write your message and press enter...(write "exit" to stop)
        Hello, Server!
        Hello, Server!
        JSC is perfectly working :)
        JSC is perfectly working :)
        exit
        ----------- Bye :) -----------
        anonymous disconnected!
        

πŸš€ Proof of Concept:

  1. Gameholic

πŸ—ƒοΈ Project Structure

STATUS IDE

JSC
β”œβ”€β”€ JConnection
β”‚Β Β  β”œβ”€β”€ JConnection.iml
β”‚Β Β  β”œβ”€β”€ pom.xml
β”‚Β Β  β”œβ”€β”€ src
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ main
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── jsc
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ jConnection
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JCloseEventConsumer.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JConnection.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  └── JConnectionManager.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ jEventManager
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JEventCode.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JEventConsumer.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JEventDataSender.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JEventManager.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  └── JEventType.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”œβ”€β”€ jMessageHandler
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JFileConsumer.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JMessageCode.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JMessageConsumer.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JMessageDelimiter.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JMessageFormatHandler.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JMessageSender.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      β”‚Β Β  └── JMessageType.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      └── jObjectParser
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β          β”œβ”€β”€ JObjectParseException.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β          └── JObjectParser.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── resources
β”‚Β Β  β”‚Β Β  └── test
β”‚Β Β  β”‚Β Β      └── java
β”‚Β Β  β”‚Β Β          └── jsc
β”‚Β Β  β”‚Β Β              └── jConnection
β”‚Β Β  β”‚Β Β                  └── JConnectionTest.java
β”‚Β Β  └── target
β”‚Β Β      β”œβ”€β”€ classes
β”‚Β Β      β”‚Β Β  └── jsc
β”‚Β Β      β”‚Β Β      β”œβ”€β”€ jConnection
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JCloseEventConsumer.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JConnection.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  └── JConnectionManager.class
β”‚Β Β      β”‚Β Β      β”œβ”€β”€ jEventManager
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JEventCode.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JEventConsumer.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JEventDataSender.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JEventManager.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  └── JEventType.class
β”‚Β Β      β”‚Β Β      β”œβ”€β”€ jMessageHandler
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JFileConsumer.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JMessageCode.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JMessageConsumer.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JMessageDelimiter.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JMessageFormatHandler.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  β”œβ”€β”€ JMessageSender.class
β”‚Β Β      β”‚Β Β      β”‚Β Β  └── JMessageType.class
β”‚Β Β      β”‚Β Β      └── jObjectParser
β”‚Β Β      β”‚Β Β          β”œβ”€β”€ JObjectParseException.class
β”‚Β Β      β”‚Β Β          └── JObjectParser.class
β”‚Β Β      β”œβ”€β”€ generated-sources
β”‚Β Β      β”‚Β Β  └── annotations
β”‚Β Β      β”œβ”€β”€ generated-test-sources
β”‚Β Β      β”‚Β Β  └── test-annotations
β”‚Β Β      └── test-classes
β”‚Β Β          └── jsc
β”‚Β Β              └── jConnection
β”‚Β Β                  └── JConnectionTest.class
β”œβ”€β”€ JSERVER
β”‚Β Β  β”œβ”€β”€ JSERVER.iml
β”‚Β Β  β”œβ”€β”€ pom.xml
β”‚Β Β  β”œβ”€β”€ src
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ main
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”œβ”€β”€ java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β  └── jsc
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β      └── jServer
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β          β”œβ”€β”€ JClientConnectionsHandler.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β          β”œβ”€β”€ JConnectionHandler.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β          β”œβ”€β”€ JRequestManager.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β          β”œβ”€β”€ JResponseSender.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β          β”œβ”€β”€ JServer.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  β”‚Β Β          └── JSocketConsumer.java
β”‚Β Β  β”‚Β Β  β”‚Β Β  └── resources
β”‚Β Β  β”‚Β Β  └── test
β”‚Β Β  β”‚Β Β      └── java
β”‚Β Β  β”‚Β Β          β”œβ”€β”€ EchoJRequestManagerImpl.java
β”‚Β Β  β”‚Β Β          └── EchoServer.java
β”‚Β Β  └── target
β”‚Β Β      β”œβ”€β”€ classes
β”‚Β Β      β”‚Β Β  └── jsc
β”‚Β Β      β”‚Β Β      └── jServer
β”‚Β Β      β”‚Β Β          β”œβ”€β”€ JClientConnectionsHandler.class
β”‚Β Β      β”‚Β Β          β”œβ”€β”€ JConnectionHandler.class
β”‚Β Β      β”‚Β Β          β”œβ”€β”€ JRequestManager.class
β”‚Β Β      β”‚Β Β          β”œβ”€β”€ JResponseSender.class
β”‚Β Β      β”‚Β Β          β”œβ”€β”€ JServer$RequestHandlerNotFound.class
β”‚Β Β      β”‚Β Β          β”œβ”€β”€ JServer.class
β”‚Β Β      β”‚Β Β          └── JSocketConsumer.class
β”‚Β Β      β”œβ”€β”€ generated-sources
β”‚Β Β      β”‚Β Β  └── annotations
β”‚Β Β      β”œβ”€β”€ generated-test-sources
β”‚Β Β      β”‚Β Β  └── test-annotations
β”‚Β Β      └── test-classes
β”‚Β Β          β”œβ”€β”€ EchoJRequestManagerImpl.class
β”‚Β Β          └── EchoServer.class
└── libs
    β”œβ”€β”€ JConnection.jar
    └── JSERVER.jar

47 directories, 59 files

*click any of the above highlighted file to navigate to its source code

About

A robust, flexible, and generalized java server-client API (JSC) built on top of the java socket interface and raw TCP. JSC also supports event-driven architecture for communication.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages