Topic subject: A Simple Client Server Multicasting
Posted: Thu Oct 16, 2008 5:59 pm
Joined: Tue Mar 27, 2007 10:55 pm Posts: 2277 Location: Earth Has thanked: 39 time Have thanks: 61 time
* Project Name:
A Simple Client Server Multicasting * Programmer:S Balasubramanian * Type:Network * Technology:Java * IDE:ANY * Description:NetConference Implementing 1-2-M Conference, Means One Server Responds to Many Clients. It Provides users about Basic Info about Netconference, Multicasting aswell as Multitherading in Java.
Code:
/* Client Setting
NetConference. ______________
*/
/* Tips to run this : __________________
(After compiling chatkaro12mserver.java)
Step1: Open another prompt and run java chatkaro12mclient 127.0.0.1. ___________________________________
*/
/*
Server Setting
** NetConference** __________________
*/
/* Tips to run this: __________________
Step1: Open command prompt and run java chatkaro12mserver. ______________________
Step2: Continue with client program.
*/
//Code: chatkaro12mserver.java // Program Starts...
void client() { try { if(hostname.equals("local")) hostname=null; InetAddress serverAddr= InetAddress.getByName(hostname); sock=new Socket(serverAddr.getHostName(),port); remoteOut=new DataOutputStream(sock.getOutputStream()); System.out.println("Connected to server " + serverAddr.getHostName() + " on port " + sock.getPort()); new chatkaro12mClientReceive(this).start(); } catch(IOException e) { System.out.println(e.getMessage() + " : Failed to connect to server."); } } protected void finalize() throws Throwable { try { if(remoteOut != null) remoteOut.close(); if(sock != null) sock.close(); } catch(IOException x) {} super.finalize(); } class WindowExitHandler extends WindowAdapter { public void windowClosing(WindowEvent e) { Window w=e.getWindow(); w.setVisible(false); w.dispose(); System.exit(0); } }
class EXIT implements ActionListener { public void actionPerformed(ActionEvent e) { if((JOptionPane.showConfirmDialog(new Frame(),"Are You Sure to close the Session?"))==JOptionPane.YES_OPTION) { JOptionPane.showMessageDialog(new Frame(),"Thank U. Visit Again. ","Good Bye",0); System.exit(0); }
} } class TextActionHandler implements ActionListener { public void actionPerformed(ActionEvent e) { try { remoteOut.writeUTF(sendText.getText()); JOptionPane.showMessageDialog(new Frame(),"Your msg has been sent ","Confirmation",0); sendText.setText(""); } catch(IOException x) { System.out.println(x.getMessage() + " : connection to peer lost."); } } } } class chatkaro12mClientReceive extends Thread { private chatkaro12mClient chat; chatkaro12mClientReceive(chatkaro12mClient chat) { this.chat=chat; } public synchronized void run() { String s; DataInputStream remoteIn=null; try { remoteIn= new DataInputStream(chat.sock.getInputStream()); while(true) { s=remoteIn.readUTF(); chat.receivedText.setText(s); } } catch(IOException e) { System.out.println(e.getMessage() + " : connection to peer lost."); } finally { try { if(remoteIn !=null) remoteIn.close(); } catch(IOException x) {} } } }
_________________ Currenlty programming with : java , html , php , and javascript . (OCJP-6 certified )