My favorites | Sign in
Project Logo
                
Changes to /trunk/server/test/src/org/jogre/protocol/TestConnectionThread.java
r2 vs. r14   Edit
  Compare: vs.   Format:
Revision r14
Go to: 
Project members, sign in to write a code review
/trunk/server/test/src/org/jogre/protocol/TestConnectionThread.java   r2 /trunk/server/test/src/org/jogre/protocol/TestConnectionThread.java   r14
1 /* 1 /*
2 * JOGRE (Java Online Gaming Real-time Engine) - Server 2 * JOGRE (Java Online Gaming Real-time Engine) - Server
3 * Copyright (C) 2004 Bob Marks (marksie531@yahoo.com) 3 * Copyright (C) 2004 Bob Marks (marksie531@yahoo.com)
4 * http://jogre.sourceforge.org 4 * http://jogre.sourceforge.org
5 * 5 *
6 * This program is free software; you can redistribute it and/or 6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License 7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2 8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version. 9 * of the License, or (at your option) any later version.
10 * 10 *
11 * This program is distributed in the hope that it will be useful, 11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License 16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software 17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */ 19 */
20 package org.jogre.protocol; 20 package org.jogre.protocol;
21 21
22 import java.io.BufferedReader; 22 import java.io.BufferedReader;
23 import java.io.IOException; 23 import java.io.IOException;
24 import java.io.PrintStream; 24 import java.io.PrintStream;
25 import java.net.UnknownHostException; 25 import java.net.UnknownHostException;
26 import java.net.Socket; 26 import java.net.Socket;
27 import java.util.Collections; 27 import java.util.Collections;
28 import java.util.LinkedList; 28 import java.util.LinkedList;
29 import java.util.List; 29 import java.util.List;
30 30
31 import nanoxml.XMLElement; 31 import nanoxml.XMLElement;
32 32
33 import org.jogre.common.AbstractConnectionThread; 33 import org.jogre.common.AbstractConnectionThread;
34 import org.jogre.common.SocketBasedMessageBus;
34 import org.jogre.common.TransmissionException; 35 import org.jogre.common.TransmissionException;
35 import org.jogre.common.comm.ITransmittable; 36 import org.jogre.common.comm.ITransmittable;
36 37
37 /** 38 /**
38 * Test connection for connecting to a JogreServer. 39 * Test connection for connecting to a JogreServer.
39 * 40 *
40 * @author Bob Marks 41 * @author Bob Marks
41 * @version Alpha 0.2.3 42 * @version Alpha 0.2.3
42 */ 43 */
43 public class TestConnectionThread extends AbstractConnectionThread { 44 public class TestConnectionThread extends AbstractConnectionThread {
44 45
45 private static final String SERVER = "localhost"; 46 private static final String SERVER = "localhost";
46 private static final int PORT = 1790; 47 private static final int PORT = 1790;
47 48
48 private String username; 49 private String username;
49 50
50 private Socket socket; 51 private Socket socket;
51 private BufferedReader in; 52 private BufferedReader in;
52 private PrintStream out; 53 private PrintStream out;
53 54
54 private boolean loop = true; 55 private boolean loop = true;
55 56
56 private List messageQueue; 57 private List messageQueue;
57 58
58 /** 59 /**
59 * @param username 60 * @param username
60 */ 61 */
61 public TestConnectionThread () throws UnknownHostException, IOException { 62 public TestConnectionThread () throws UnknownHostException, IOException {
62 super(null); 63 super(new SocketBasedMessageBus(new Socket (SERVER, PORT)));
63 setSocket (new Socket (SERVER, PORT));
64 messageQueue = Collections.synchronizedList(new LinkedList()); 64 messageQueue = Collections.synchronizedList(new LinkedList());
65 } 65 }
66 66
67 /** 67 /**
68 * change "send (ITransmittable message)" method visibility to public. 68 * change "send (ITransmittable message)" method visibility to public.
69 * 69 *
70 * @param message 70 * @param message
71 */ 71 */
72 public void send (ITransmittable message) { 72 public void send (ITransmittable message) {
73 super.send(message); 73 super.getMessageBus().send(message);
74 } 74 }
75 75
76 /** 76 /**
77 * Recieve a XML element back to the user. 77 * Recieve a XML element back to the user.
78 * 78 *
79 * @return 79 * @return
80 */ 80 */
81 public XMLElement receive () throws IOException { 81 public XMLElement receive () throws IOException {
82 if (messageQueue.size() > 0) { 82 if (messageQueue.size() > 0) {
83 return (XMLElement) messageQueue.remove(0); 83 return (XMLElement) messageQueue.remove(0);
84 } else { 84 } else {
85 return null; 85 return null;
86 } 86 }
87 } 87 }
88 88
89 /* (non-Javadoc) 89 /* (non-Javadoc)
90 * @see org.jogre.common.AbstractConnectionThread#parse(nanoxml.XMLElement) 90 * @see org.jogre.common.AbstractConnectionThread#parse(nanoxml.XMLElement)
91 */ 91 */
92 public void parse (XMLElement message) throws TransmissionException { 92 public void parse (XMLElement message) throws TransmissionException {
93 messageQueue.add(message); 93 messageQueue.add(message);
94 } 94 }
95 95
96 /* (non-Javadoc) 96 /* (non-Javadoc)
97 * @see org.jogre.common.AbstractConnectionThread#cleanup() 97 * @see org.jogre.common.AbstractConnectionThread#cleanup()
98 */ 98 */
99 public void cleanup() { 99 public void cleanup() {
100 100
101 } 101 }
102 } 102 }
Hosted by Google Code