Crossfire JXClient, Trunk  R20561
DefaultServerConnection.java
Go to the documentation of this file.
1 /*
2  * This file is part of JXClient, the Fullscreen Java Crossfire Client.
3  *
4  * JXClient is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * JXClient is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with JXClient; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  *
18  * Copyright (C) 2005-2008 Yann Chachkoff.
19  * Copyright (C) 2006-2011 Andreas Kirschbaum.
20  */
21 
22 package com.realtime.crossfire.jxclient.server.server;
23 
28 import java.io.IOException;
29 import org.jetbrains.annotations.NotNull;
30 import org.jetbrains.annotations.Nullable;
31 
38 public class DefaultServerConnection implements ServerConnection {
39 
43  @NotNull
44  private final ClientSocket clientSocket;
45 
53  public DefaultServerConnection(@NotNull final Model model, @Nullable final DebugWriter debugProtocol) throws IOException {
54  clientSocket = new ClientSocket(model, debugProtocol);
55  }
56 
60  public void start() {
61  clientSocket.start();
62  }
63 
68  public void stop() throws InterruptedException {
69  clientSocket.stop();
70  }
71 
75  @Override
76  public void addClientSocketListener(@NotNull final ClientSocketListener clientSocketListener) {
77  clientSocket.addClientSocketListener(clientSocketListener);
78  }
79 
83  @Override
84  public void removeClientSocketListener(@NotNull final ClientSocketListener clientSocketListener) {
85  clientSocket.removeClientSocketListener(clientSocketListener);
86  }
87 
95  public void writePacket(@NotNull final byte[] packet, final int length) {
96  clientSocket.writePacket(packet, length);
97  }
98 
102  @Override
103  public void connect(@NotNull final String hostname, final int port) {
104  clientSocket.connect(hostname, port);
105  }
106 
110  @Override
111  public void disconnect(@NotNull final String reason) {
112  clientSocket.disconnect(reason, false);
113  }
114 
115 }
void writePacket(@NotNull final byte[] packet, final int length)
Writes a Crossfire Message on the socket, so it is sent to the server.
void disconnect(@NotNull final String reason, final boolean isError)
Terminates the connection.
void addClientSocketListener(@NotNull final ClientSocketListener clientSocketListener)
Adds a ClientSocketListener to be notified.
Writer debug information to a log file.
One of the two most important classes, ServerConnection performs most of the network-related work...
Combines all model classes that are updated.
Definition: Model.java:44
void disconnect(@NotNull final String reason)
Disconnects from the server.Does nothing if not connected. the reason for the disconnect ...
void removeClientSocketListener(@NotNull final ClientSocketListener clientSocketListener)
Removes a ClientSocketListener to notify.the client socket listener to remove
Interface for listeners interested in ClientSocket related events.
void writePacket(@NotNull final byte[] buf, final int len)
Writes a packet.
void connect(@NotNull final String host, final int port)
Connects to a server.
void addClientSocketListener(@NotNull final ClientSocketListener clientSocketListener)
Adds a ClientSocketListener to notify.the client socket listener to add
DefaultServerConnection(@NotNull final Model model, @Nullable final DebugWriter debugProtocol)
Creates a new instance.
void removeClientSocketListener(@NotNull final ClientSocketListener clientSocketListener)
Removes a ClientSocketListener to be notified.
final ClientSocket clientSocket
The ClientSocket instance used to connect to Crossfire servers.
void connect(@NotNull final String hostname, final int port)
Attempts to connect the client to a server.the hostname to connect to the port to connect to ...