Hello friends this is RAGHAVENDRA, I am doing a client server program to play a video file, when I run both client and server programs I still not getting any outputs and even I am not getting ERRORS please help me to get rid of this problem.
client.java
import java.awt.Color; import java.awt.Component; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.IOException; import java.io.ObjectOutputStream; import java.net.MalformedURLException; import java.net.Socket; import java.net.UnknownHostException; import javax.media.CannotRealizeException; import javax.media.Manager; import javax.media.NoPlayerException; import javax.media.Player; import javax.swing.BorderFactory; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; public class client extends JFrame { clientreceive cr; JPanel p; public void init() { clientreceive cr = new clientreceive(); } public client() { getContentPane().setLayout(null); getContentPane().setBackground(Color.WHITE); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JLabel l = new JLabel("enter file name"); l.setBounds(50, 30, 100, 50); getContentPane().add(l); final JTextField t = new JTextField(); t.setBounds(160, 45, 100, 30); getContentPane().add(t); JButton b = new JButton("go"); b.setBounds(145, 100, 50, 30); getContentPane().add(b); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { sendREQ(t.getText()); } }); JButton b1 = new JButton("play"); b1.setBounds(145, 130, 70, 30); getContentPane().add(b1); b1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { mediaPlayer(cr.lrecFile.getAbsolutePath(),p); } }); JPanel p = new JPanel(); p.setBorder(BorderFactory.createTitledBorder("Videoplayer")); p.setBounds(125, 200, 300, 300); getContentPane().add(p); setSize(600,600); setVisible(true); } protected void mediaPlayer(final String Path, final JPanel panel) { new Thread() { public void run() { try { Player p = Manager.createRealizedPlayer(new File (Path) .toURL()); Component ctrlpanel = p.getControlPanelComponent(); Component player = p.getVisualComponent(); player.setBounds(10, 20, 300, 170); ctrlpanel.setBounds(10, 191, 300, 20); panel.add(player); panel.add(ctrlpanel); panel.repaint(); p.start(); System.out.println(" Player Started"); } catch (NoPlayerException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (CannotRealizeException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.start(); } protected void sendREQ(String text) { try { Socket soc = new Socket("localhost", 4576); ObjectOutputStream oos = new ObjectOutputStream( soc.getOutputStream()); oos.writeObject("REQ"); oos.writeObject(text); System.out.println(text); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String args[]) { new client(); }
}
clientreceive.java import java.io.File; import java.io.FileOutputStream; import java.io.ObjectInputStream; import java.net.ServerSocket; import java.net.Socket; import javax.swing.JOptionPane; public class clientreceive { File lrecFile; Socket soc; ServerSocket serSoc; ObjectInputStream ois; clientreceive() { receive(); } private void receive() { try { System.out.println("Inside clientreceive"); serSoc = new ServerSocket(4576); while (true) { soc = serSoc.accept(); ois = new ObjectInputStream(soc.getInputStream()); String str = (String) ois.readObject(); checkStatus(str); } } catch (Exception e) { e.printStackTrace(); } } private void checkStatus(String str) { try { if (str.equals("REP")) { byte[] file = (byte[]) ois.readObject(); String filename = (String) ois.readObject(); String scn = (String) ois.readObject(); lrecFile = new File("RecFiles/" + scn + "" + filename); FileOutputStream fos = new FileOutputStream(lrecFile); fos.write(file); fos.close(); JOptionPane.showMessageDialog(null, "Last Received File is:" + lrecFile.getAbsolutePath()); } else if (str.equals("NoFile")) { JOptionPane.showMessageDialog(null, "The User Requested File Not Found."); } } catch (Exception e) { e.printStackTrace(); } }
}
server.java import java.io.File; import java.io.FileInputStream; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.net.ServerSocket; import java.net.Socket; import javax.swing.JOptionPane; public class server { private Socket soc; private ServerSocket serSoc; private ObjectInputStream ois; server() { try { serSoc = new ServerSocket(4576); while (true) { soc = serSoc.accept(); ois = new ObjectInputStream(soc.getInputStream()); String str = (String) ois.readObject(); checkStatus(str); } } catch (Exception e) { e.printStackTrace(); } } private void checkStatus(String str) { try { if (str.equals("REQ")) { String file = (String) ois.readObject(); System.out.println("inside ck status"); process(file); } } catch (Exception e) { e.printStackTrace(); } } private void process(String file) { try { System.out.println("inside process"); File file2 = new File("ServerDB/" + file); if (file2.exists() == false) { JOptionPane.showMessageDialog(null, "The User Requested File Not Found. "); } FileInputStream fis = new FileInputStream(file2); byte[] b = new byte[fis.available()]; fis.read(b); fis.close(); Socket socket = new Socket("localhost",4576); ObjectOutputStream oos = new ObjectOutputStream( socket.getOutputStream()); oos.writeObject("REP"); oos.writeObject(b); oos.writeObject(file2.getName()); } catch (Exception e) { e.printStackTrace(); } } public static void main(String args[]) { new server(); }
}
Ads