0

I was trying to create a socket program in JAVA using eclipse. I have the server and client code ready but I am not understanding how to run the code in eclipse for the server and client in the same project. Should I 1] have main method in both the server and the client and start running them individually, or 2] Should I use threads to run each of them separately, or 3] If I were to add another client in the network then how do I run that as well.

Please do help me and let me know which method should I adopt.

Thanks for your help.

3 Answers 3

2

You can do either #1 or #2. Eclipse has no issue with running/debugging multiple Java processes concurrently, nor is there anything invalid about having a single Java process that starts up both the server and client on separate threads.

However, I would suggest that in the real world it is most likely that you will not always be starting the server and client processes on the same machine, at the same time. So I think option #1 makes the most sense. You server and client apps should be able to run independently of each other, whether you're inside of Eclipse or not.

So if you do #1, then to add another client to the network you simply spin up another client process, the same way you did with the first client (Right click on the class -> Run As -> Java Application). You can start as many as you like that way. Though if you want to start up a bunch of them (like, say, for load testing), then consider creating another class with its own main() method that just spins up a bunch of clients on separate threads.

Sign up to request clarification or add additional context in comments.

Comments

0

I think it would be better if you put individual main methods in the client and the server. This helps with the debugging and would help you determine which client is currently running if each client is run separately.

Comments

0

You can probably have a server java class file with main method and this is started by the eclipse. You can also have a client java class which have multi threaded to start a few clients. To identify the interaction between the server and the client, you can enable debug perspective in eclipse. This link should be able to give you idea on how you can start coding.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.