Create a server that should run always using sockets or some other technology [closed]

General Tech Technology & Software 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Technology & Software related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I've a task here and I am unable to finalize and not sure what technology opt my problem. Here is the explanation of my problem. My application is stand alone application and will deploy in different locations. Lets say LocA, LocB and so on. Each location has its own clients some clients are connected via LAN and some are third party clients. As long as if the clients are connected via LAN no problem of requesting and response. But there will be few clients which are not connected via LAN.

To the third party clients we will provide IP and PORT to connect and request for data in a standard HL7 format. The problem here is the clients can create their own client program by using any technology. They may use Socket programming, .NET socket programming and so on. But our server should accept connections from clients what ever the technology it is, process their requests and respond back to them. And the requirement is the server program should run always and listens to the allotted ports or whenever there is a request to specific port then start our server program and process the client request and respond back to client.

Please pardon me if my English confuses you. Please give me a solution for my problem.

Note : Client program can be any technology and any programming language. That is up to client which way they want to use to connect with server and send their requests.

profilepic.png
manpreet 2 years ago

I am giving a small example here, that how client and server works with Socket, i am also including the multithreading on the Server side.

Client side code:

public class ClientWala {

    public static void main(String[] args) throws Exception{

        Boolean b = true;
    Socket s = new Socket("127.0.0.1", 4444);

    System.out.println("connected: "+s.isConnected());


    OutputStream output = s.getOutputStream();
    PrintWriter pw = new PrintWriter(output,true);

    // to write data to server
    while(b){

        if (!b){

             System.exit(0);
        }

        else {
            pw.write(new Scanner(System.in).nextLine());
        }
    }


    // to read data from server
    InputStream input   = s.getInputStream();
    InputStreamReader isr = new InputStreamReader(input);
    BufferedReader br = new BufferedReader(isr);
    String data = null;

    while ((data = br.readLine())!=null){

        // Print it using sysout, or do whatever you want with the incoming data from server

    }




    }
}

0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.