need Advice / Help

HI.. i have a program here that works as a simple chat program...

i have Strider.java as the server and Hiryu.java as the client...

my question is, althoug it is already running, the server and client

can't meet each other.

the server can't detect if there's a connection or the client can't connect

i can't see if there's really a connection happen..

could they please help me solve my problem. i have here

the codes of my program..

//Strider.java

import java.io.*;

import java.net.*;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class Strider extends JFrame implements ActionListener

{

ObjectOutputStream output;

ObjectInputStream input;

String msg;

JTextField txtfld;

JTextArea txtarea;

public Strider()

{

Container c = getContentPane();

c.setLayout(new FlowLayout());

txtfld = new JTextField(10);

txtarea = new JTextArea(10,20);

txtfld.addActionListener(this);

c.add(txtfld);

c.add(new JScrollPane(txtarea));

setSize(230,250);

show();

}

public void actionPerformed(ActionEvent e)

{

sendData(e.getActionCommand());

}

public void runStrider()

{

ServerSocket server;

Socket connection;

int counter = 1;

try {

server = new ServerSocket(5000, 100);

while(true){

txtarea.setText("Waiting for someone to connect");

connection = server.accept();

txtarea.append("Connection" + counter + "received from:" + connection.getInetAddress().getHostName());

output = new ObjectOutputStream(connection.getOutputStream());

output.flush();

input = new ObjectInputStream(connection.getInputStream());

txtarea.append("\n Got I/O Streams \n");

msg = "Server>> Connection Successful";

output.writeObject(msg);

output.flush();

do{

try{

msg = (String) input.readObject();

txtarea.append("\n" + msg);

txtarea.setCaretPosition(txtarea.getText().length());

}

catch(ClassNotFoundException cnfex){

txtarea.append("\nUnknown Object type received");

}

}while(!msg.equals("Client>> Terminate"));

txtarea.append("\nUser Terminated connection");

output.close();

input.close();

connection.close();

++counter;

}

}

catch(EOFException eof){

System.out.println("Client terminated connection");

}

catch(IOException io){

io.printStackTrace();

}

}

public void sendData(String s)

{

try{

output.writeObject("Server>>" + s);

output.flush();

txtarea.append("\nServer>>" + s);

}

catch(IOException cnfex){

txtarea.append("\nError writing Object");

}

}

public static void main(String[] args)

{

Strider app = new Strider();

app.addWindowListener(

new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

}

);

app.runStrider();

}

}

//Hiryu.java

import java.io.*;

import java.net.*;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class Hiryu extends JFrame implements ActionListener

{

ObjectOutputStream output;

ObjectInputStream input;

String msg;

JTextField txtfld;

JTextArea txtarea;

public Hiryu()

{

Container c = getContentPane();

c.setLayout(new FlowLayout());

txtfld = new JTextField(10);

txtarea = new JTextArea(10,20);

txtfld.addActionListener(this);

c.add(txtfld);

c.add(new JScrollPane(txtarea));

setSize(230,250);

show();

}

public void actionPerformed(ActionEvent e)

{

sendData(e.getActionCommand());

}

public void runClient()

{

Socket client;

try {

txtarea.setText("Attempting Connection\n");

client = new Socket(InetAddress.getByName("127.168.2.109"), 5000);

txtarea.append("Connected to:" + client.getInetAddress().getHostName());

output = new ObjectOutputStream(client.getOutputStream());

output.flush();

input = new ObjectInputStream(client.getInputStream());

txtarea.append("\n Got I/O Streams \n");

msg = "Server>> Connection Successful";

output.writeObject(msg);

output.flush();

do{

try{

msg = (String) input.readObject();

txtarea.append("\n" + msg);

txtarea.setCaretPosition(txtarea.getText().length());

}

catch(ClassNotFoundException cnfex){

txtarea.append("\nUnknown Object type received");

}

}while(!msg.equals("Server>> Terminate"));

txtarea.append("\nUser Terminated connection");

output.close();

input.close();

client.close();

//++counter;

}

catch(EOFException eof){

System.out.println("Client terminated connection");

}

catch(IOException io){

io.printStackTrace();

}

}

public void sendData(String s)

{

try{

output.writeObject("Client>>" + s);

output.flush();

txtarea.append("\nClient>>" + s);

}

catch(IOException cnfex){

txtarea.append("\nError writing Object");

}

}

public static void main(String[] args)

{

Hiryu app = new Hiryu();

app.addWindowListener(

new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

}

);

app.runClient();

}

}

[5795 byte] By [strider_hiryu007a] at [2007-11-27 7:57:21]
# 1
You're not honestly expecting someone to go through all that unformated code are you? Please learn how to use code tags. http://forum.java.sun.com/help.jspa?sec=formatting
petes1234a at 2007-7-12 19:39:12 > top of Java-index,Java Essentials,New To Java...
# 2

i'm sory for the inconvinience, here's the formated one..

it's not really my intention.. my mistake..

still, would they help me please?

//Strider.java

import java.io.*;

import java.net.*;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class Strider extends JFrame implements ActionListener

{

ObjectOutputStream output;

ObjectInputStream input;

String msg;

JTextField txtfld;

JTextArea txtarea;

public Strider()

{

Container c = getContentPane();

c.setLayout(new FlowLayout());

txtfld = new JTextField(10);

txtarea = new JTextArea(10,20);

txtfld.addActionListener(this);

c.add(txtfld);

c.add(new JScrollPane(txtarea));

setSize(230,250);

show();

}

public void actionPerformed(ActionEvent e)

{

sendData(e.getActionCommand());

}

public void runStrider()

{

ServerSocket server;

Socket connection;

int counter = 1;

try {

server = new ServerSocket(5000, 100);

while(true){

txtarea.setText("Waiting for someone to connect");

connection = server.accept();

txtarea.append("Connection" + counter + "received from:" + connection.getInetAddress().getHostName());

output = new ObjectOutputStream(connection.getOutputStream());

output.flush();

input = new ObjectInputStream(connection.getInputStream());

txtarea.append("\n Got I/O Streams \n");

msg = "Server>> Connection Successful";

output.writeObject(msg);

output.flush();

do{

try{

msg = (String) input.readObject();

txtarea.append("\n" + msg);

txtarea.setCaretPosition(txtarea.getText().length());

}

catch(ClassNotFoundException cnfex){

txtarea.append("\nUnknown Object type received");

}

}while(!msg.equals("Client>> Terminate"));

txtarea.append("\nUser Terminated connection");

output.close();

input.close();

connection.close();

++counter;

}

}

catch(EOFException eof){

System.out.println("Client terminated connection");

}

catch(IOException io){

io.printStackTrace();

}

}

public void sendData(String s)

{

try{

output.writeObject("Server>>" + s);

output.flush();

txtarea.append("\nServer>>" + s);

}

catch(IOException cnfex){

txtarea.append("\nError writing Object");

}

}

public static void main(String[] args)

{

Strider app = new Strider();

app.addWindowListener(

new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

}

);

app.runStrider();

}

}

//Hiryu.java

import java.io.*;

import java.net.*;

import java.awt.*;

import javax.swing.*;

import java.awt.event.*;

public class Hiryu extends JFrame implements ActionListener

{

ObjectOutputStream output;

ObjectInputStream input;

String msg;

JTextField txtfld;

JTextArea txtarea;

public Hiryu()

{

Container c = getContentPane();

c.setLayout(new FlowLayout());

txtfld = new JTextField(10);

txtarea = new JTextArea(10,20);

txtfld.addActionListener(this);

c.add(txtfld);

c.add(new JScrollPane(txtarea));

setSize(230,250);

show();

}

public void actionPerformed(ActionEvent e)

{

sendData(e.getActionCommand());

}

public void runClient()

{

Socket client;

try {

txtarea.setText("Attempting Connection\n");

client = new Socket(InetAddress.getByName("127.168.2.109"), 5000);

txtarea.append("Connected to:" + client.getInetAddress().getHostName());

output = new ObjectOutputStream(client.getOutputStream());

output.flush();

input = new ObjectInputStream(client.getInputStream());

txtarea.append("\n Got I/O Streams \n");

msg = "Server>> Connection Successful";

output.writeObject(msg);

output.flush();

do{

try{

msg = (String) input.readObject();

txtarea.append("\n" + msg);

txtarea.setCaretPosition(txtarea.getText().length());

}

catch(ClassNotFoundException cnfex){

txtarea.append("\nUnknown Object type received");

}

}while(!msg.equals("Server>> Terminate"));

txtarea.append("\nUser Terminated connection");

output.close();

input.close();

client.close();

//++counter;

}

catch(EOFException eof){

System.out.println("Client terminated connection");

}

catch(IOException io){

io.printStackTrace();

}

}

public void sendData(String s)

{

try{

output.writeObject("Client>>" + s);

output.flush();

txtarea.append("\nClient>>" + s);

}

catch(IOException cnfex){

txtarea.append("\nError writing Object");

}

}

public static void main(String[] args)

{

Hiryu app = new Hiryu();

app.addWindowListener(

new WindowAdapter()

{

public void windowClosing(WindowEvent e)

{

System.exit(0);

}

}

);

app.runClient();

}

}

strider_hiryu007a at 2007-7-12 19:39:12 > top of Java-index,Java Essentials,New To Java...
# 3
> i'm sory for the inconvinience, here's the formated> one..Try again. :-)And make sure you copy/paste from the original, properly indented source. If you take what's on this page, you'll still have no indendting.
jverda at 2007-7-12 19:39:12 > top of Java-index,Java Essentials,New To Java...
# 4
> i'm sory for the inconvinience, here's the formated> one..> it's not really my intention.. my mistake..> still, would they help me please?> You didn't read my link did you? Sigh....
petes1234a at 2007-7-12 19:39:12 > top of Java-index,Java Essentials,New To Java...
# 5
> You didn't read my link did you? Sigh....Read? What are you talking about. If you can't copy and paste people aren't interested.
floundera at 2007-7-12 19:39:12 > top of Java-index,Java Essentials,New To Java...
# 6

> > You didn't read my link did you? Sigh....

>

> Read? What are you talking about. If you can't copy

> and paste people aren't interested.

? was this to me or the OP?

To the OP. Here again is the link about code formating that you should read before any repeat attempt at posting code:

http://forum.java.sun.com/help.jspa?sec=formatting

Message was edited by:

petes1234

petes1234a at 2007-7-12 19:39:12 > top of Java-index,Java Essentials,New To Java...
# 7
Sorry Pete. I was having a sideswipe at all those that don't want to do their own research/work and demand solutions delivered on a silver platter.
floundera at 2007-7-12 19:39:12 > top of Java-index,Java Essentials,New To Java...