LArex

Server

May 23rd, 2012
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. /*
  2. * To change this template, choose Tools | Templates
  3. * and open the template in the editor.
  4. */
  5. package javaandrotest;
  6.  
  7. import java.io.*;
  8. import java.net.ServerSocket;
  9. import java.net.Socket;
  10. import java.util.Date;
  11.  
  12. /**
  13. *
  14. * @author bennet.hentschel
  15. */
  16. public class Server {
  17.  
  18. private static ServerSocket server;
  19.  
  20. /**
  21. * @param args the command line arguments
  22. */
  23. public static void main(String[] args) throws IOException {
  24. server = new ServerSocket(80);
  25.  
  26. Socket client = null;
  27. try {
  28. client = server.accept();
  29. System.out.println(client.toString());
  30. OutputStream outputStream = client.getOutputStream();
  31. ObjectOutputStream s = new ObjectOutputStream(outputStream);
  32. s.writeObject(new Date(11333377));
  33. System.out.println("wrote Object");
  34. s.flush();
  35. } catch (IOException e) {
  36. e.printStackTrace();
  37. } finally {
  38. if (client != null) {
  39. try {
  40. client.close();
  41. } catch (IOException e) {
  42. e.printStackTrace();
  43. }
  44. }
  45. }
  46. }
  47.  
  48. public static void send(Object a) {
  49. try {
  50. FileOutputStream out = new FileOutputStream("theTime");
  51. ObjectOutputStream s = new ObjectOutputStream(out);
  52. s.writeObject(a);
  53. s.flush();
  54. } catch (Exception ex) {
  55. System.out.println(ex.toString());
  56. }
  57.  
  58. }
  59. }
Advertisement
Add Comment
Please, Sign In to add comment