Kindly log in to use this feature. We’ll take you to the login page automatically.
LoginGeneral Tech Technology & Software 3 years ago
User submissions are the sole responsibility of contributors, with TuteeHUB disclaiming liability for accuracy, copyrights, or consequences of use; content is for informational purposes only and not professional advice.
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
}
}
}
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.
Kindly log in to use this feature. We’ll take you to the login page automatically.
LoginReady to take your education and career to the next level? Register today and join our growing community of learners and professionals.
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
Your experience on this site will be improved by allowing cookies. Read Cookie Policy
manpreet
Best Answer
3 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.