Search code examples
javasocketsnetworkingconsensus

What are the other ways of creating a server out of a client than just implementing a Consensus algorithm?


So I have got this project where I have to create a client-server app which can communicate between connected nodes (connected devices with that app). It should be only on a local network (L2 segment, margined by routers). Through the network, nodes are able to communicate. Every node can send a message to either all nodes or to just one (specific) node.

  • server can be either static or dynamic
  • app will assure that there are not 2 servers - for the TCP/IP network and for the chosen port

And I am wondering how to do that when server is shut down, clients during the heartbeat will know that it is and create a new server (one of clients). I was thinking of either Consensus algorithm or Lamport clock - where you wait till all clients have sent their messages and the client that received them first will become a server, but first of all I am would appreciate an easier solution and secondly I have no idea how to implement these into code.


Solution

  • What i might do is , before any action between the server and client , or maybe every 5 actions (depends on the performance you need) i would make a checkStatus method to check that the server is up. if else the client would chose one to make it a server. But i don't know why you need to do that , generally the client is a normal computer and the server have a high computational power. you would have also a lot of issues on the level of Security and Memory.

    If i really understand what you need, (i had the same task in my university, i think i can help you out. you need a peer to peer application and a server application in the same project. The client would check the server if he has files (for example) or that he can access them. if he can, then he downloads them. if the client can't access to a specific folder or a file in the server, he can check other clients if they have those files from the server stored in their storage and they can seed him or just one of them if you want to make it easier. when i did this program, i wasn't good enough, so i stored information in text files (every client have a text file of file's names available) and the server also had a text-based database.

    to be brief, What you need:

    • Client application (can do peer to peer operation or operate with server)
    • Server application
    • Data Base for the server and mini databases for the clients.
    • communication using ftp or whatever protocol you need for your application.

    Edit : My answer was a bit too vague as i din't fully understood what you need , i've made some research , and i think you can achieve what you want with atomix A reactive Java framework for building fault-tolerant distributed systems. you can check the website.