Serve entire objects using ObjectOutputStream : Server « Network Protocol « Java

Java
1. 2D Graphics GUI
2. 3D
3. Advanced Graphics
4. Ant
5. Apache Common
6. Chart
7. Collections Data Structure
8. Database SQL JDBC
9. Design Pattern
10. Development Class
11. Email
12. Event
13. File Input Output
14. Game
15. Hibernate
16. J2EE
17. J2ME
18. JDK 6
19. JSP
20. JSTL
21. Language Basics
22. Network Protocol
23. PDF RTF
24. Regular Expressions
25. Security
26. Servlets
27. Spring
28. Swing Components
29. Swing JFC
30. SWT JFace Eclipse
31. Threads
32. Tiny Application
33. Velocity
34. Web Services SOA
35. XML
Microsoft Office Word 2007 Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Java » Network Protocol » ServerScreenshots 
Serve entire objects using ObjectOutputStream
Serve entire objects using ObjectOutputStream

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Hashtable;

public class ObjServer {
  public static void main(String args[]) throws Exception {
    ServerSocket ssock = new ServerSocket(1234);
    Hashtable hash = new Hashtable();
    hash.put("Java Source and Support""www.java2s.com");

    while (true) {
      System.out.println("Listening");
      Socket sock = ssock.accept();

      ObjectOutputStream ostream = new ObjectOutputStream(sock
          .getOutputStream());
      ostream.writeObject(hash);
      ostream.close();
      sock.close();
    }
  }
}

// A Java-specific client can read objects from Java servers.

class ObjClient {
  public static void main(String[] argsthrows Exception {
    Socket sock = new Socket(args[0]1234);
    ObjectInputStream ois = new ObjectInputStream(sock.getInputStream());
    Hashtable hash = (Hashtableois.readObject();
    System.out.println(hash);
    ois.close();
    sock.close();
  }
}

           
       
Related examples in the same category
1. A generic framework for a flexible, multi-threaded server
2. Server allows connections on socket 6123Server allows connections on socket 6123
3. This server displays messages to a single clientThis server displays messages to a single client
4. The client can specify information to control the output of a serverThe client can specify information to control the output of a server
5. A server can use specialized streams to deliver typed dataA server can use specialized streams to deliver typed data
6. A multithreaded serverA multithreaded server
7. Base class to build multithreaded servers easily
8. Manage a pool of threads for clients
9. Client estimates the speed of the network connection to the server
10. Socket Openeration Test
11. URL Connection Test URL Connection Test
12. This server retrieves the time using the RFC867 protocol.This server retrieves the time using the RFC867 protocol.
13. Quote Server
14. Client and Server Demo
15. Reflector
w___w_w__._j___a___v___a_2__s_.__c___o_m__ | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.