aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Trying to create a Console Based Chat app Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Trying to create a Console Based Chat app" Watch "Trying to create a Console Based Chat app" New topic
Author

Trying to create a Console Based Chat app

Harshil Mavani
Greenhorn

Joined: Jul 04, 2014
Posts: 11
Hello, Everyone!
I am trying to create a console based chat app which to people can use over the net.. But first i want to test it if the concerned parties are on the same LAN.
Now my program works well on my PC Alone. viz. If I run both modules on my PC

The Client Code:


And The server code is :


The Program works like a dream on two different PC's on the same LAN
I wish to use it on two different PC's on different LAN Also it works only if Firewall is turned off on My PC ( Server PC ).

How do i scale it the Net?
And any suggestions regarding the Firewall Issue?

Thank you
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41900
    
  63
The server needs to accept incoming connections on port 6606, there's no way around that. You don't need to turn off the firewall to achieve that (in fact you shouldn't), but you will need to open up that port.

You may also wish to search these forums, as many people before you have asked about writing chat clients, there should be useful information available already.


Ping & DNS - my free Android networking tools app
Harshil Mavani
Greenhorn

Joined: Jul 04, 2014
Posts: 11
Ulf, Thank you for your reply
I tried running it with the firewall ON. It doesn't work. Both the modules freeze and soon throw an Exception. Will adding an Exception rule in windows help?
If yes, Can you guide me with the same?

Thanks again
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41900
    
  63
I'm unfamiliar with the Windows firewall, so I don't know how it can be configured. But I'm certain that having it turned on will block most ports, and certainly non-standard ones. So you need to find out how to configure it. The first result I get when googling "windows firewall opening port" looks extremely promising.
Harshil Mavani
Greenhorn

Joined: Jul 04, 2014
Posts: 11
Hey Ulf,
I got the firewall problem. Thanks to your advice
Now one last doubt. This code works for 2 Laptops connected to same router. I want it to run on 2 PC's running somewhere else altogether. Any clue?
Thanks once again
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41900
    
  63
What problem are you facing doing that?
Harshil Mavani
Greenhorn

Joined: Jul 04, 2014
Posts: 11
Ulf Dittmer wrote:What problem are you facing doing that?

Currently i have only one issue. If i run the Client app on my friend's PC who is not present in my neighborhood, the client app throws and Exception viz. Could not connect exception. Is there another process or maybe some other way to connect two PC's on two different networks?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18850
    
  40

Harshil Mavani wrote:
Ulf Dittmer wrote:What problem are you facing doing that?

Currently i have only one issue. If i run the Client app on my friend's PC who is not present in my neighborhood, the client app throws and Exception viz. Could not connect exception. Is there another process or maybe some other way to connect two PC's on two different networks?


You are not providing us with enough information... There is a whole world of connection issues when trying to connect two different networks.

Can both PC reach the internet? And if so, how? ... Are there other firewalls? Are you behind routers? NAT services (ie. private networks)? etc. etc. In other words, we can't answer your question, unless we know the end to end setup.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Harshil Mavani
Greenhorn

Joined: Jul 04, 2014
Posts: 11
I am sorry. I am new to networking in Java. My aim was to create a chat app for personal use. Now i know there's facebook and other social networking sites which help you chat seamlessly, my intention was to gain a deeper understanding for the same with practical knowledge. And of course, Show off :P
Overall i wanted to make an app which is dynamic. and yes, both parties do have connection to the internet. One may be behind a router and other maybe on a modem. But, I'd like to start small where both have firewalls down and both on the same type of connection viz. Both behind different routers etc.
Thanks
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41900
    
  63
The key point is that port 6066 of the server must be reachable from the client - is that the case? telnet ip.address.of.server 6066 will tell you.
Harshil Mavani
Greenhorn

Joined: Jul 04, 2014
Posts: 11
Ulf Dittmer wrote:The key point is that port 6066 of the server must be reachable from the client - is that the case? telnet ip.address.of.server 6066 will tell you.


Exactly where the app fails. The server is reachable but to what extent, I don't know
When i used two laptops connected to the same Router, it worked. When a friend of mine (who is somewhere else.) tried connecting, it did not work. AND during that time, My server was running. But due to some other reason the client was unable to connect.
Thank you.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18850
    
  40

Harshil Mavani wrote:
Ulf Dittmer wrote:The key point is that port 6066 of the server must be reachable from the client - is that the case? telnet ip.address.of.server 6066 will tell you.


Exactly where the app fails. The server is reachable but to what extent, I don't know
When i used two laptops connected to the same Router, it worked. When a friend of mine (who is somewhere else.) tried connecting, it did not work. AND during that time, My server was running. But due to some other reason the client was unable to connect.


And those reasons have less to do with the two computers, and more to do with all the routers, firewalls, and switches in between. Take for example, what you did so far -- you disable (or corrected) a firewall issue. Well, do you have any other firewalls? If you are running in some corporate machine, then there is a chance you are.

So, how to start? First, I would recommend that you check to see if you are in a private network. My bet is that you are. Most home private networks have an IP address that start with of 192.168.*.*. Many corporate / business private networks have IP addresses that start with 10.*.*.*.

Remember, for these private networks to get to the internet, they are configured to go out to the internet. In your case, with the chat app, you need to get out to the internet *and* then get back into the private network on the other side. So, you need specific network configurations to enable what you want.

Henry
Harshil Mavani
Greenhorn

Joined: Jul 04, 2014
Posts: 11
Wow. Amazing oberservation henry. Thanks a lot. Any tutorial you can suggest? I am really interested to dig more. And yes. My IP is 192.168.*.*
Please suggest some tutorial. Thanks again everyone.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18850
    
  40

Harshil Mavani wrote:Wow. Amazing oberservation henry. Thanks a lot. Any tutorial you can suggest? I am really interested to dig more. And yes. My IP is 192.168.*.*
Please suggest some tutorial. Thanks again everyone.


Sorry. I don't have a tutorial for you. Regardless, there is little to no changes that need to be done from the Java applications anyway. This is mostly a networking configuration issue.

Anyway, assuming that your client needs to go over the internet to get to your server ... from the server side, "google what is my ip address". Google will tell you your server's public ip address. This is the address to get to the server application on the internet. This is *not* the IP address of your server's PC, it is just the access point from the internet to your private network. This is the public IP address for the piece of equipment that is used by machines in your private network to access the internet.

Change the client to access the Server's public IP address. And that is the full extent of what can be done application-wise.


Now... You need to contact your system administrator (for the server side), and ask for the TCP port number 6066 to be forwarded (from that internet access point) to your PC (that is running the server application). It would also be a good idea, if the network is using a DHCP server, to take your PC off of it, and to give it a fixed private address too.

Henry
Harshil Mavani
Greenhorn

Joined: Jul 04, 2014
Posts: 11
Thanks a lot Henry. It has helped me a lot.
It's a wrap folks
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Trying to create a Console Based Chat app