This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes GUI chat program Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "GUI chat program" Watch "GUI chat program" New topic
Author

GUI chat program

sam wayne
Greenhorn

Joined: Jul 09, 2013
Posts: 3
I have made command line multi client chat program but am having trouble in making GUI based,,, I am very confused about my approach(howmany classes should i make, how shoud i arrange them, which part shoud be GUI and where ....etc.)

One of main problems is that the server starts with the 1st instance of chat program and rest all instances (of chat program) just instantiate client...if 1st instance of chat program is closed,,,server is closed for all...
How to instantiate server with one chat instance but make it stoppable by all other instances(of chat program)...?

Can someone suggest me something(approach for starting and soln for given problm).
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

sam wayne wrote:One of main problems is that the server starts with the 1st instance of chat program and rest all instances (of chat program) just instantiate client...


Welcome to the Ranch, Sam!

But that's rather a strange design. In a real client-server application the server would run all the time, waiting for connections from clients. The idea that a client would start the server if it can't find a server is not very practical -- what happens if two clients start up at the same time and both start "the" server? And how is the second client supposed to look for the server when any other client on any other computer might already have started it?

So I'd suggest you go with the ordinary design where the server runs as a standalone application on a predefined machine at a predefined port, and the clients connect to that server.
sam wayne
Greenhorn

Joined: Jul 09, 2013
Posts: 3
Thanks.. you are right..I was little confused...
I have made a servergui.java and clientgui.java , they work perfectly when I start server and then desired no of clients...can you tell me how to combine them in one Application so that 1st time it is launched a server is created alongwith a client and for rest only clients are created. .
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

sam wayne wrote:can you tell me how to combine them in one Application so that 1st time it is launched a server is created alongwith a client and for rest only clients are created. .


No. Not "can't" but "won't", because I already tried to explain why that wasn't a practical idea. Are you particularly attached to that idea? If so, why?
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41062
    
  43
You can't start the server on some random machine where the first client to be started happens to run, because then the other clients won't know which machine to connect to. As Paul said, client and server run independently of one another. What are you trying to achieve by integrating them?


Ping & DNS - my free Android networking tools app
sam wayne
Greenhorn

Joined: Jul 09, 2013
Posts: 3
Got it.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: GUI chat program
 
Similar Threads
Java chat application implementation method
Server Socket for chat
Can I use the same port
How to approach a very simple P2P communication program.
Chat application implementation method?