ObjectInputStream and ObjectOutputStream from Socket : Socket « Network Protocol « Java

Home
Java
1.2D Graphics GUI
2.3D
3.Advanced Graphics
4.Ant
5.Apache Common
6.Chart
7.Class
8.Collections Data Structure
9.Data Type
10.Database SQL JDBC
11.Design Pattern
12.Development Class
13.EJB3
14.Email
15.Event
16.File Input Output
17.Game
18.Generics
19.GWT
20.Hibernate
21.I18N
22.J2EE
23.J2ME
24.JavaFX
25.JDK 6
26.JDK 7
27.JNDI LDAP
28.JPA
29.JSP
30.JSTL
31.Language Basics
32.Network Protocol
33.PDF RTF
34.Reflection
35.Regular Expressions
36.Scripting
37.Security
38.Servlets
39.Spring
40.Swing Components
41.Swing JFC
42.SWT JFace Eclipse
43.Threads
44.Tiny Application
45.Velocity
46.Web Services SOA
47.XML
Java » Network Protocol » Socket 




ObjectInputStream and ObjectOutputStream from Socket
      

import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.InetAddress;
import java.net.Socket;

public class LoopingSocketClient {

  public static void main(String args[]) throws Exception {
    Socket socket1;
    int portNumber = 1777;
    String str = "";

    socket1 = new Socket(InetAddress.getLocalHost(), portNumber);

    ObjectInputStream ois = new ObjectInputStream(socket1.getInputStream());

    ObjectOutputStream oos = new ObjectOutputStream(socket1.getOutputStream());

    str = "initialize";
    oos.writeObject(str);

    while ((str = (Stringois.readObject()) != null) {
      System.out.println(str);
      oos.writeObject("bye");

      if (str.equals("bye bye"))
        break;
    }

    ois.close();
    oos.close();
    socket1.close();
  }

}

   
    
    
    
    
    
  














Related examples in the same category
1.Create a socket without a timeout
2.Create a socket with a timeout
3.Demonstrate Sockets.
4.Socket connection and concurrent package
5.XML based message
6.ServerSocket and Socket for Serializable object
7.String based communication between Socket
8.Get email with Socket
9.Create PrintWriter from BufferedWriter, OutputStreamWriter and Socket
10.Read from server
11.Use Socket to read and write stream
12.Connects to a server at a specified host and port. It reads text from the console and sends it to the server
13.A simple network client that establishes a network connection to a specified port on a specified host, send an optional message across the connection
14.Reading Text from a Socket
15.Writing Text to a Socket
16.Sending a POST Request Using a Socket
17.Get the Date from server
18.Transfer a file via Socket
19.Ping a server
20.Read and write through socket
21.Read float number from a Socket
22.Read Object from Socket
23.deleting messages from a POP3 mailbox based on message size and Subject line
24.A timeout feature on socket connections
25.Write Objects From Socket
26.Write Double Using Sockets
27.Download WWW Page
28.Redirects incoming TCP connections to other hosts/ports
29.Socket Fetcher
30.Socket Address Encoder
31.Zip socket
32.This program shows how to interrupt a socket channel.
33.This program shows how to use sockets to send plain text mail messages.
34.Makes a socket connection to the atomic clock in Boulder, Colorado, and prints the time that the server sends.
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.