2
* JBoss, Home of Professional Open Source
3
* Copyright 2005, JBoss Inc., and individual contributors as indicated
4
* by the @authors tag. See the copyright.txt in the distribution for a
5
* full listing of individual contributors.
7
* This is free software; you can redistribute it and/or modify it
8
* under the terms of the GNU Lesser General Public License as
9
* published by the Free Software Foundation; either version 2.1 of
10
* the License, or (at your option) any later version.
12
* This software is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15
* Lesser General Public License for more details.
17
* You should have received a copy of the GNU Lesser General Public
18
* License along with this software; if not, write to the Free
19
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
23
/* Created on Jul 24, 2005
26
package org.jboss.remoting.samples.multiplex;
28
import java.io.ObjectInputStream;
29
import java.io.ObjectOutputStream;
30
import java.net.ServerSocket;
31
import java.net.Socket;
33
import org.jboss.remoting.transport.multiplex.VirtualServerSocket;
34
import org.jboss.remoting.transport.multiplex.VirtualSocket;
41
* @author <a href="mailto:r.sigal@computer.org">Ron Sigal</a>
43
public class PrimeScenarioExampleClient
45
public void runPrimeScenario()
49
// create a VirtualSocket and connect it to MasterServerSocket
50
Socket v1 = new VirtualSocket("localhost", 5555);
52
// do some asynchronous input in a separate thread
53
new AsynchronousThread(v1).start();
55
// do some synchronous communication
56
ObjectOutputStream oos = new ObjectOutputStream(v1.getOutputStream());
57
ObjectInputStream ois = new ObjectInputStream(v1.getInputStream());
58
oos.writeObject(new Integer(3));
59
Integer i1 = (Integer) ois.readObject();
60
System.out.println("synch: " + i1);
71
class AsynchronousThread extends Thread
73
private Socket virtualSocket;
75
AsynchronousThread(Socket virtualSocket)
77
this.virtualSocket = virtualSocket;
84
// create a VirtualServerSocket that shares a port with socket
85
ServerSocket serverSocket = new VirtualServerSocket(virtualSocket.getLocalPort());
87
// create a VirtualSocket that shares a port with socket
88
serverSocket.setSoTimeout(10000);
89
Socket v4 = serverSocket.accept();
90
ObjectInputStream ois = new ObjectInputStream(v4.getInputStream());
92
// get an object from the server
93
v4.setSoTimeout(10000);
94
Object o = ois.readObject();
95
System.out.println("asynch: " + ((Integer) o));
108
public static void main(String[] args)
110
new PrimeScenarioExampleClient().runPrimeScenario();