Win a copy of TDD for a Shopping Website LiveProject this week in the Testing 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:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

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
 
It's never done THAT before. Explain it to me tiny ad:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
    Bookmark Topic Watch Topic
  • New Topic