This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Sockets and Internet Protocols and the fly likes problem in simple chat application. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply locked New topic
Author

problem in simple chat application.

Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 931
hello i m trying to write a chat application..
but i m getting few errors in the code, here is the code:

Server1.java


Client.java


The first problem i m getting is, i am able to connect to my network only (i mean able to communicate with those machines which are in my network/same network), how do i connect to others networks??
The second problem is i can communicate only to one machine/client at a time, if other is trying to run client.java (shows no error), but not able to communicate??

how do i solve these two problems??
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:
The first problem i m getting is, i am able to connect to my network only (i mean able to communicate with those machines which are in my network/same network), how do i connect to others networks??


If the host you're connecting to isn't on your LAN, then either it has to have a public IP address, or it has to be behind a router that has a public IP address and that is doing port-forwarding to that host.

Private Network
Port Forwarding

Note that the normal way to run a chat application isn't to have all the participants directly connect to each other. Rather, they all connect to a central server that does have a public IP address, and that server acts as a relay for the messages.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:
The second problem is i can communicate only to one machine/client at a time, if other is trying to run client.java (shows no error), but not able to communicate??


What do you mean? What exact problem are you having if you try to run two clients? I notice that your server only allows one connection over its lifetime. Is that what you're asking about? How to connect multiple clients to the same server?

A server is usually structured something like:



Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 931

How to connect multiple clients to the same server?


yes i mean by this.
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:

How to connect multiple clients to the same server?


yes i mean by this.


And did you read the rest of my post? Do you understand what you need to do now?
Punit Jain
Ranch Hand

Joined: Aug 20, 2011
Posts: 931
yes i read, but i don't understand, i need more explanation..
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Punit Jain wrote:yes i read, but i don't understand, i need more explanation..


That is addressed in your new thread: http://www.coderanch.com/t/572867/sockets/java/do-port-forwarding-java
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in simple chat application.
 
Similar Threads
simple socket program not working right
still not solved
i want create a simple chat with private rooms
client-serer...plz help
Client server communication programme