|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectnet.petterroea.starterkit.ClientSideConnection
public class ClientSideConnection
Represents the client side connection in a game if you want multiplayer ;)
This is beta code, so i cannot guarantee that it works
| Field Summary | |
|---|---|
private java.net.Socket |
client
The socket that connects to the server |
boolean |
connected
True if we are connected |
private java.net.InetSocketAddress |
endPoint
Server |
java.util.LinkedList<Packet> |
in
Clear the list after reading from it. |
(package private) java.lang.Thread |
inListener
The thread that listens |
private boolean |
listening
False if packet listeners should stop |
java.util.LinkedList<Packet> |
out
LinkedList of packets going out |
(package private) java.lang.Thread |
outListener
The thread the sends |
private java.io.BufferedReader |
reader
Server to client packet reader |
static java.lang.Object |
synch
Use this to synchronize |
private java.io.PrintWriter |
writer
Client to server packet writer |
| Constructor Summary | |
|---|---|
ClientSideConnection(java.lang.String ip,
int port)
Constructor for a connection to a server. |
|
| Method Summary | |
|---|---|
Packet |
getPacket(java.lang.String[] msg)
Used to recognize packets by their prefix. |
void |
startListening()
Starts listening. |
void |
stopListening()
Stops listening for packets. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static java.lang.Object synch
public java.util.LinkedList<Packet> in
public java.util.LinkedList<Packet> out
private java.net.Socket client
private boolean listening
java.lang.Thread inListener
java.lang.Thread outListener
private java.io.BufferedReader reader
private java.io.PrintWriter writer
private java.net.InetSocketAddress endPoint
public boolean connected
| Constructor Detail |
|---|
public ClientSideConnection(java.lang.String ip,
int port)
throws java.io.IOException
ip - The ip adressport - The port to be used. REMEMBER TO TELL USERS WHAT PORT THE GAME USES FOR COMMUNICATION. http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers is a important reference. Also, here is a tip: Let the user choose port, but supply a standardport
java.io.IOException - if something goes wrong while connecting| Method Detail |
|---|
public void stopListening()
throws java.lang.InterruptedException,
java.io.IOException
java.lang.InterruptedException - If the listeners could not be joined
java.io.IOException - If unable to close the connectionpublic void startListening()
public Packet getPacket(java.lang.String[] msg)
msg - The contents of the packet that has just arrived from the serverside
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||