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.
24
* Created on Jul 24, 2005
26
package org.jboss.remoting.samples.multiplex;
28
import java.io.IOException;
29
import java.io.ObjectInputStream;
30
import java.io.ObjectOutputStream;
31
import java.net.ServerSocket;
32
import java.net.Socket;
34
import org.jboss.remoting.transport.multiplex.MasterServerSocket;
35
import org.jboss.remoting.transport.multiplex.VirtualSocket;
42
* @author <a href="mailto:r.sigal@computer.org">Ron Sigal</a>
44
public class PrimeScenarioExampleServer
46
public void runPrimeScenario()
50
// create a MasterServerSocket and get a VirtualSocket
51
ServerSocket serverSocket = new MasterServerSocket(5555);
52
serverSocket.setSoTimeout(10000);
53
Socket v2 = serverSocket.accept();
55
// do some asynchronous communication in a separate thread
56
Thread asynchronousThread = new AsynchronousThread(v2);
57
asynchronousThread.start();
59
// do some synchronous communication
60
ObjectInputStream ois = new ObjectInputStream(v2.getInputStream());
61
ObjectOutputStream oos = new ObjectOutputStream(v2.getOutputStream());
62
v2.setSoTimeout(10000);
63
Object o = ois.readObject();
66
asynchronousThread.join();
79
class AsynchronousThread extends Thread
81
private Socket virtualSocket;
83
public AsynchronousThread(Socket socket) throws IOException
85
this.virtualSocket = socket;
92
// Give VirtualServerSocket a chance to start.
95
// connect to VirtualServerSocket
96
String hostName = virtualSocket.getInetAddress().getHostName();
97
int port = virtualSocket.getPort();
98
Socket v3 = new VirtualSocket(hostName, port);
100
// send an object to the client
101
ObjectOutputStream oos = new ObjectOutputStream(v3.getOutputStream());
102
oos.writeObject(new Integer(7));
117
public static void main(String[] args)
119
new PrimeScenarioExampleServer().runPrimeScenario();