• Post Reply 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Networked Programs that work across countries

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do I make networked programs work across countries or at least in the same city. I just want to know how I can make networked programs work outside my network.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Writing networked applications that are on the same network isn't fundamentally different from ones that run at opposite ends of the earth. What kind of communication pattern are you envisioning - one-to-one, one-to-many/many-to-one or many-to-many?

Keep in mind that firewalls in between communicating applications may block some of the ports you intend to use.
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
many-to-many

Its a chat program
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For chat, socket communication is probably best. You will have problems getting through firewalls that are not open for whatever port you end up using.

You'll need to think about how chat client A will know about chat client B (i.e, its IP address). Some form of central control seems necessary for this.
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have made the chat program using sockets, it works perfectly within my home network but does not work outside. I am trying to find out if I can make the same thing work across countries.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"does not work" is not a very useful problem description. It gives us nothing on which base our advice. How does it not work? Are there error messages? TellTheDetails

Have you made sure there is no firewall in between that blocks connections?
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, there is defintely a firewall between them, I think there are 2, the windows firewall and the norton internet security firewall. I used port 6000 but I dont think that the firewall is stopping it because it works perfectly in my home network...Do you think that I should use port 80, since firewalls wont think the internet port is suspicious?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You shouldn't use any port that is well-defined for some other protocol. Any port below 1024 may anyway cause problems for Unix-ish OSes (where permissions may not allow those ports to be used).
 
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are running into commercial firewalls, such as used in corporate environments, you can only reliably use two ports: 80 and 443.

Nearly all corporate IT network folks block all other ports.

While you can have your program use any port over 1000, that's unlikely to work in a corporate space.

And many consumer firewalls also prevent access to other than a small subset of ports., typically something like 25, 53, 80, 110, 443, and a few others.
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
let me try those ports, but im just curious, if 80 is the internet port, what is 443?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
80 is the default for HTTP, 443 is the default for HTTPS.

You might want to bookmark http://www.faqs.org/rfcs/rfc1700.html
[ August 25, 2008: Message edited by: Ulf Dittmer ]
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The thing is that I connected to an other unsecured network ad tried to acsess the program on my other computer (on port 80) but it still failed
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What does "it failed" mean? What software -if any- was running on port 80 of that machine? TellTheDetails
[ August 25, 2008: Message edited by: Ulf Dittmer ]
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you know what NAT is, and what it does? Do you know how to configure port forwarding on your home router, or why you would want to? Do you understand the difference between peer-to-peer protocols and client-server protocols? This is all well-understood material; you don't necessarily need to be working to solve any problems, but rather just to learn about the problem space some more. Do some reading about NAT and router configuration, and you may come to understand the issues here much better.
 
Pat Farrell
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
BTW, this seems to me to be more of a general networking, or sockets question, rather than one about classic distributed Java using RMI, Corba, etc.

Perhaps a move is in order?
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im not sure if there are any programs running on port 80...How do I find out?
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that Firefox was running on port 80 at that time
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Firefox is a client, not a server, so it wouldn't be running on any port. You can use any web browser to check whether there is anything running on port 80 by pointing it to "http://x.y.z.w/", substituting the IP address of the machine for "x.y.z.w".
 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Devasia Manuel:
How do I make networked programs work across countries or at least in the same city. I just want to know how I can make networked programs work outside my network.



The same way you make local network programs (more or less).
Probably your problem is not a java problem, but an IP problem.

If your address is a private one, which most cerainly is, you simply cannot be reached from outside.

The same applies to the other side of the communication (if it has a private address, cannot be reached).

You need to develop a chat server a publish it.
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and when I say "It failes", I means that I got a:

java.net.ConnectException: Connection timed out: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333) at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:519)
at java.net.Socket.connect(Socket.java:469)
at java.net.Socket.<init>(Socket.java:366)
at java.net.Socket.<init>(Socket.java:180)
at FileTransfer_Client.Client.connect(Client.java:119)
at FileTransfer_Client.Client.main(Client.java:113)
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and just so that it may help anyone, I will post my code for the Client and Server (Note: My programs are made in Netbeans so ignore th GUI part):
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Server:


package Server;

import java.net.InetAddress;
import javax.swing.UIManager;


public class Main extends javax.swing.JFrame {

static Main s=new Main();

String ipAddress;

public Main() {
initComponents();
}



// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jLabel1 = new javax.swing.JLabel();
ipAddress_textfield = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
jLabel2 = new javax.swing.JLabel();
port_textfield = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
username_textfield = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("TalkALot Server");

jTextArea1.setColumns(20);
jTextArea1.setEditable(false);
jTextArea1.setLineWrap(true);
jTextArea1.setRows(5);
jTextArea1.setText("To enable unlimited talking with TalkALot, \nyou first must set up a server where \nclients can connect to...Simply enter the \ndetails and click Start!!");
jScrollPane1.setViewportView(jTextArea1);

jLabel1.setText("IP Address: ");

ipAddress_textfield.setEditable(false);

jButton1.setText("Start!!");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
startButtonListener(evt);
}
});

jLabel2.setText("Port Number: ");

port_textfield.setText("6000");

jLabel3.setText("Username: ");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 369, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addGap(104, 104, 104)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(username_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(port_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ipAddress_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)))))
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(167, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(157, 157, 157))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(18, 18, 18)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1)
.addComponent(ipAddress_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel2)
.addComponent(port_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(username_textfield, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(18, 18, 18)
.addComponent(jButton1)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void startButtonListener(java.awt.event.ActionEvent evt) {

Variables.port=Integer.parseInt(port_textfield.getText());
Variables.username=username_textfield.getText();
s.setVisible(false);

Thread server=new Thread(new Server());
Thread client=new Thread(new Client());
server.start();
client.start();

}


public static void main(String args[]) {

try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());} catch (Exception e){}

s.setVisible(true);
s.setIP();



}

void setIP(){

try{ipAddress=InetAddress.getLocalHost().toString();System.out.println(ipAddress);}catch (Exception e){}
String tokens[]=ipAddress.split("/");
Variables.ipAddress=tokens[1];
System.out.println("IP Address= "+tokens[1]);
Variables.username=tokens[0];
System.out.println("Username= "+tokens[0]);

ipAddress_textfield.setText(tokens[1]);
username_textfield.setText(tokens[0]);

}

// Variables declaration - do not modify
private javax.swing.JTextField ipAddress_textfield;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTextField port_textfield;
private javax.swing.JTextField username_textfield;
// End of variables declaration

}

package Server;

import java.io.*;
import java.net.*;
import java.util.*;

public class Server implements Runnable {

ArrayList<PrintWriter> clientOutputStreams;

String message;

public class ClientHandler implements Runnable {

BufferedReader reader;

Socket sock;


public ClientHandler(Socket clientSocket) {
try {
sock = clientSocket;
InputStreamReader isReader = new InputStreamReader(sock.getInputStream());
reader = new BufferedReader(isReader);

} catch(Exception ex) {ex.printStackTrace();}
} // close constructor

public void run() {


try {

while ((message = reader.readLine()) != null) {

checkMessage();


System.out.println("read " + message);
tellEveryone(message);

} // close while
} catch(Exception ex) {ex.printStackTrace();}
} // close run
} // close inner class

void checkMessage(){

try{
if(message.contains("102594627847241004627836582")){

System.out.println("Message contains code");
String[] user=message.split("}");
System.out.println("Split Correctly");
System.out.println("Array length: "+user.length);
System.out.println("user[0]="+user[0]);
System.out.println("user[1]="+user[1]);
message=user[1]+" has joined the chat";
System.out.println("It is a username");
}
} catch (Exception e){
System.out.println("It is not a username");
e.printStackTrace();
}
}


public void run(){
main();
}

void main () {
go();
}

public void go() {

System.out.print("Server Started!!");

clientOutputStreams = new ArrayList<PrintWriter>();

try {
ServerSocket serverSock = new ServerSocket(Variables.port);

while(true) {
Socket clientSocket = serverSock.accept();
PrintWriter writer = new PrintWriter(clientSocket.getOutputStream());
clientOutputStreams.add(writer);

Thread t = new Thread(new ClientHandler(clientSocket));
t.start();


System.out.println("got a connection");
}
// now if I get here I have a connection

}catch(Exception ex) {
ex.printStackTrace();
}
}

public void tellEveryone(String message) {

Iterator it = clientOutputStreams.iterator();
while(it.hasNext()) {
try {
PrintWriter writer = (PrintWriter) it.next();
writer.println(message);
writer.flush();
} catch(Exception ex) {
ex.printStackTrace();
}

} // end while

} // close tellEveryone


}


package Server;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.net.*;
import java.io.*;
import java.io.BufferedWriter.*;
import static java.lang.System.*;
import java.util.Calendar.*;
import java.util.Date.*;
import java.util.Date;
import javax.swing.*;

public class Client extends javax.swing.JFrame implements WindowListener, Runnable {

Socket sock;

BufferedReader reader;

PrintWriter writer;

public Client() {

initComponents();

}

public void run(){
main();
}



// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();
incoming = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
outgoing = new javax.swing.JTextArea();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
ipAddress = new javax.swing.JLabel();
port = new javax.swing.JLabel();
username = new javax.swing.JLabel();
send_button = new javax.swing.JButton();

setTitle("TalkALot");

incoming.setColumns(20);
incoming.setEditable(false);
incoming.setLineWrap(true);
incoming.setRows(5);
jScrollPane1.setViewportView(incoming);

outgoing.setColumns(20);
outgoing.setLineWrap(true);
outgoing.setRows(5);
jScrollPane2.setViewportView(outgoing);

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Information"));

jLabel1.setText("IP Address: ");

jLabel2.setText("Port: ");

jLabel3.setText("Username: ");

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(username, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(port, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
.addComponent(ipAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE))))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(ipAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3)
.addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
);

send_button.setText("Send");
send_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
send_button(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE)
.addComponent(send_button, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(send_button)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void send_button(java.awt.event.ActionEvent evt) {

try {
writer.println(Variables.username+": "+outgoing.getText());
writer.flush();

} catch(Exception ex) {
ex.printStackTrace();
}
outgoing.setText("");
outgoing.requestFocus();

}


void main() {

try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}catch (Exception e){e.printStackTrace();}

Client c=new Client();

c.setVisible(true);
c.setInfo();
c.start();


}

void setInfo(){


ipAddress.setText(Variables.ipAddress);
username.setText(Variables.username);
port.setText(Variables.port+"");

}

void start(){
setUpNetworking();
Thread readerThread = new Thread(new IncomingReader());
readerThread.start();

}

void setUpNetworking() {
try {
sock = new Socket(Variables.ipAddress, Variables.port);
InputStreamReader streamReader = new InputStreamReader(sock.getInputStream());
reader = new BufferedReader(streamReader);

writer = new PrintWriter(sock.getOutputStream());

System.out.println("networking established");

try {
writer.println("102594627847241004627836582"+"}"+Variables.username);
writer.flush();

} catch(Exception ex) {
ex.printStackTrace();
}
} catch(IOException ex) {
ex.printStackTrace();
}
} // close setUpNetworking

public class IncomingReader implements Runnable {
public void run() {
String message;
try {

while ((message = reader.readLine()) != null) {
System.out.println("read " + message);
incoming.append(message + "\n");

} // close while
} catch(Exception ex) {ex.printStackTrace();}
} // close run
} // close inner class

// Variables declaration - do not modify
private javax.swing.JTextArea incoming;
private javax.swing.JLabel ipAddress;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea outgoing;
private javax.swing.JLabel port;
private javax.swing.JButton send_button;
private javax.swing.JLabel username;
// End of variables declaration


public void windowOpened(WindowEvent e) {

}

public void windowClosing(WindowEvent e) {
writer.println(Variables.username+" has left the chat");
}

public void windowClosed(WindowEvent e) {

}

public void windowIconified(WindowEvent e) {

}

public void windowDeiconified(WindowEvent e) {

}

public void windowActivated(WindowEvent e) {

}

public void windowDeactivated(WindowEvent e) {

}

}
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Client:




package Client;


class Variables {

static String ipAddress;
static String port;
static String username;

Variables(String user, String ip, String port1){

username=user;
ipAddress=ip;
port=port1;

System.out.println(username+" "+ipAddress+" "+port);

}

}


package Client;

import java.net.*;
import java.io.*;
import java.io.BufferedWriter.*;
import static java.lang.System.*;
import java.util.Calendar.*;
import java.util.Date.*;
import java.util.Date;
import javax.swing.*;

public class Setup extends javax.swing.JFrame {

static Setup s=new Setup();

String port_text;

public Setup() {
initComponents();
}



// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jSeparator1 = new javax.swing.JSeparator();
username = new javax.swing.JTextField();
jLabel3 = new javax.swing.JLabel();
jLabel4 = new javax.swing.JLabel();
ipAddress = new javax.swing.JTextField();
jLabel5 = new javax.swing.JLabel();
port = new javax.swing.JTextField();
jButton1 = new javax.swing.JButton();
error = new javax.swing.JLabel();

setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
setTitle("TalkALot Setup");
setAlwaysOnTop(true);
setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

jLabel1.setText("Please type in the following information to engange in a ");

jLabel2.setText("TalkALot conversation: ");

username.setText("other");

jLabel3.setText("Username: ");

jLabel4.setText("IP Address: ");

ipAddress.setText("127.0.0.1");

jLabel5.setText("Port:");

port.setText("6000");

jButton1.setText("OK");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
ok_button_listener(evt);
}
});

error.setFont(new java.awt.Font("Tahoma", 0, 14));

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jLabel2))
.addContainerGap())
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE)
.addGroup(layout.createSequentialGroup()
.addGap(57, 57, 57)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel4)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(ipAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(jLabel5)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, 122, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(50, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(130, Short.MAX_VALUE)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(error, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1))
.addGap(112, 112, 112))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel3)
.addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jLabel4)
.addComponent(ipAddress, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel5))
.addGap(18, 18, 18)
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(error, javax.swing.GroupLayout.DEFAULT_SIZE, 14, Short.MAX_VALUE)
.addContainerGap())
);

pack();
}// </editor-fold>

private void ok_button_listener(java.awt.event.ActionEvent evt) {

try{
port_text=port.getText();

}

catch (NumberFormatException r){r.printStackTrace(); error.setText("ERROR!!");}

new Variables(username.getText(), ipAddress.getText(), port_text);

Client c=new Client();
c.main();

s.setVisible(false);


}


public static void main(String args[]) {

try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}catch (Exception e){}

s.setVisible(true);

}

// Variables declaration - do not modify
private javax.swing.JLabel error;
private javax.swing.JTextField ipAddress;
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel4;
private javax.swing.JLabel jLabel5;
private javax.swing.JSeparator jSeparator1;
private javax.swing.JTextField port;
private javax.swing.JTextField username;
// End of variables declaration

}


package Client;

import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
import java.net.*;
import java.io.*;
import java.io.BufferedWriter.*;
import static java.lang.System.*;
import java.util.Calendar.*;
import java.util.Date.*;
import java.util.Date;
import javax.swing.*;

public class Client extends javax.swing.JFrame implements WindowListener, Runnable {

Socket sock;

BufferedReader reader;

PrintWriter writer;

public Client() {

initComponents();

}

public void run(){
main();
}



// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jScrollPane1 = new javax.swing.JScrollPane();
incoming = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
outgoing = new javax.swing.JTextArea();
jPanel1 = new javax.swing.JPanel();
jLabel1 = new javax.swing.JLabel();
jLabel2 = new javax.swing.JLabel();
jLabel3 = new javax.swing.JLabel();
ipAddress = new javax.swing.JLabel();
port = new javax.swing.JLabel();
username = new javax.swing.JLabel();
send_button = new javax.swing.JButton();

setTitle("TalkALot");

incoming.setColumns(20);
incoming.setEditable(false);
incoming.setLineWrap(true);
incoming.setRows(5);
jScrollPane1.setViewportView(incoming);

outgoing.setColumns(20);
outgoing.setLineWrap(true);
outgoing.setRows(5);
jScrollPane2.setViewportView(outgoing);

jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED), "Information"));

jLabel1.setText("IP Address: ");

jLabel2.setText("Port: ");

jLabel3.setText("Username: ");

javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jLabel3)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(username, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE))
.addGroup(jPanel1Layout.createSequentialGroup()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel1)
.addComponent(jLabel2))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(port, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE)
.addComponent(ipAddress, javax.swing.GroupLayout.DEFAULT_SIZE, 223, Short.MAX_VALUE))))
.addContainerGap())
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(ipAddress, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel1))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel2)
.addComponent(port, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 7, Short.MAX_VALUE)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jLabel3)
.addComponent(username, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)))
);

send_button.setText("Send");
send_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
send_button(evt);
}
});

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 322, Short.MAX_VALUE)
.addComponent(send_button, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 301, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 43, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(send_button)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

private void send_button(java.awt.event.ActionEvent evt) {

try {
writer.println(Variables.username+": "+outgoing.getText());
writer.flush();

} catch(Exception ex) {
ex.printStackTrace();
}
outgoing.setText("");
outgoing.requestFocus();

}


void main() {

try{UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());}catch (Exception e){e.printStackTrace();}

Client c=new Client();

c.setVisible(true);
c.setInfo();
c.start();


}

void setInfo(){


ipAddress.setText(Variables.ipAddress);
username.setText(Variables.username);
port.setText(Variables.port+"");

}

void start(){
setUpNetworking();
Thread readerThread = new Thread(new IncomingReader());
readerThread.start();

}

void setUpNetworking() {
try {
sock = new Socket(Variables.ipAddress, Integer.parseInt(Variables.port));
InputStreamReader streamReader = new InputStreamReader(sock.getInputStream());
reader = new BufferedReader(streamReader);

writer = new PrintWriter(sock.getOutputStream());
writer.println(InetAddress.getLocalHost());

System.out.println("networking established");

try {
writer.println("102594627847241004627836582"+"}"+Variables.username);
writer.flush();

} catch(Exception ex) {
ex.printStackTrace();
}
} catch(IOException ex) {
ex.printStackTrace();
}
} // close setUpNetworking

public class IncomingReader implements Runnable {
public void run() {
String message;
try {

while ((message = reader.readLine()) != null) {
System.out.println("read " + message);
incoming.append(message + "\n");

} // close while
} catch(Exception ex) {ex.printStackTrace();}
} // close run
} // close inner class

// Variables declaration - do not modify
private javax.swing.JTextArea incoming;
private javax.swing.JLabel ipAddress;
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JTextArea outgoing;
private javax.swing.JLabel port;
private javax.swing.JButton send_button;
private javax.swing.JLabel username;
// End of variables declaration


public void windowOpened(WindowEvent e) {

}

public void windowClosing(WindowEvent e) {
writer.println(Variables.username+" has left the chat");
}

public void windowClosed(WindowEvent e) {

}

public void windowIconified(WindowEvent e) {

}

public void windowDeiconified(WindowEvent e) {

}

public void windowActivated(WindowEvent e) {

}

public void windowDeactivated(WindowEvent e) {

}

}
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please edit your code to UseCodeTags. People are not going to try to make sense out of that much hard-to-read code.
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Why did you ignore my post? I'm telling you: Google "NAT" (which is short for Network Address Translation) and read about it, and most likely you will immediately understand why your program isn't working from one home LAN to another.
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By the way, once you get past the networking issues, there's a bug waiting to happen in the code: Don't println to a Socket.

Moving to the Sockets forum since no distributed technologies are involved.
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ohh, sorry, I didnt see your post among all the other, ill check out Google NAT
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
NAT seems like exactly what I am looking for, I Googled it and went to wikipedia, but im not sure how to implement it into my code...
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ive also done a bit of reasearch on IPv6, I've heard that's its for worldwide use, can it help me solve my problem here? And if so, how can I use it?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
With all due respect, I think your knowledge of how TCP/IP networks work is still too limited to understand and/or tackle the issues that the problem at hand presents.

To recap just briefly: NAT isn't the solution to your problem, it's why the solution you outlined above can't work.

IP6 -like IP4- is a transport protocol. It operates at a lower level than the problems you're grappling with, and doesn't help here.

I'd suggest to read up on TCP/IP protocols (and socket networking) in detail, and in the end you'll probably agree that a pure P2P solution will not work; you'll need to resort to a server that mediates between the various clients.
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im still not sure when you mean a server that mediates betweens different clinets. Could you give a simple example + code example
 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Most routers (which implements the NAT service) provides mechanisms to punch through the firewall. In most cases, it is just an admin page that allows you to route a port to a specific machine.

Programatically, some routers support the PnP protocol, which has definitions for routers to enable a program to route a port from the external address to the NAT'ed address.


Of course, all of this may be academic, as the OP needs to have a better grasp of basic networking and routing first.

Henry
 
Henry Wong
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Devasia Manuel:
Im still not sure when you mean a server that mediates betweens different clinets. Could you give a simple example + code example



This may get complicated, but I'll give it a try... Basically, a NAT'ed network will allow machines from inside the private network out of the network, but not machines from outside the network into the private network.

For machines outside the network to get into the private network, a port must be opened for it, which will route the packet to the correct machine. (see my previous post)

Now.... A common trick, for cases where this is not possible, is to have a "packet router" service also located outside of the network. The client outside of the network must know of its existence and negotiates a connection with it first. As for the actual service inside the network, it now needs to also act like a client, and connect to this external service -- to negotiate a connection first.


This server that Ulf speaks of, is the "packet router" server, that will take these two connections, and connect them together, as if they connected to each other in the first place.

As for the "simple example + code example", you can probably guess there is no "simple" example. You will need to modify your clients. You will need to modify you chat server. And you will need to write a "packet router" server, which connects all of this together.

Henry
[ August 30, 2008: Message edited by: Henry Wong ]
 
Pat Farrell
Rancher
Posts: 4803
7
Mac OS X VI Editor Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have to say, I agree with Ulf, the OP needs to do some basic learning on networks and how to make programs talk between two computers, say in the same room, before getting into this more complex stuff.

Its not just a question of getting a code fragment to cut and paste.
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I see now, sorry for changing the subject, but can anyone tell a good book (not too complicated) where I can learn and read all this stuff?
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A very good book (in my opinion) is volume 1 of "Internetworking with TCP/IP" by Douglas Comer. It goes straight to the details, though, without much in the way of holding the reader's hand.
 
Devasia Manuel
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, thanks, I'll borrow it from the library and read it.
 
Ranch Hand
Posts: 36
Eclipse IDE Java ME Oracle
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Start with a basic networking book and also the following sites have good sources:

and when you are getting sleepy, check out these projects on sourceforge.net (open sources, you might consider join them)


enjoy!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic