Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
    Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

problem in simple chat application.

 
Ranch Hand
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
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??
 
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator


How to connect multiple clients to the same server?



yes i mean by this.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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
Posts: 1143
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator
yes i read, but i don't understand, i need more explanation..
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Report post to moderator

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



That is addressed in your new thread: https://coderanch.com/t/572867/sockets/java/do-port-forwarding-java
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
    Bookmark Topic Watch Topic
  • New Topic