Class Client
java.lang.Object
me.remigio07.chatplugin.api.server.util.socket.Client
Client socket.
Obtain instances of this class with
Client(InetAddress, int).
-
Constructor Summary
ConstructorsConstructorDescriptionClient(InetAddress serverAddress, int serverPort) Constructs a new client socket. -
Method Summary
Modifier and TypeMethodDescriptionConnects this client to its server using the given ID.voidManually disconnects this client from the server.getID()Gets this client's ID.getInput()Gets this client's data input stream.Gets this client's data output stream.Gets this client's server's address.intGets this client's server's port.Gets this client's socket.booleanChecks if this client is currently connected to the server.voidrun()Deprecated.Internal use only; do not call this method.voidsendPacket(PacketSerializer packet) Sends a packet to the server.
-
Constructor Details
-
Client
Constructs a new client socket.Call
connect(String)to connect it.- Parameters:
serverAddress- Server's addressserverPort- Server's port [0 - 65535]- Throws:
IllegalArgumentException- If port is outside of range [0 - 65535]
-
-
Method Details
-
connect
Connects this client to its server using the given ID.- Parameters:
id- Client's ID- Returns:
- Connection's outcome
- Throws:
IOException- If something goes wrongInterruptedException- If the identification task gets interrupted- See Also:
-
disconnect
Manually disconnects this client from the server.- Throws:
IOException- If something goes wrong- See Also:
-
run
Deprecated.Internal use only; do not call this method.Automatic packet listener.- See Also:
-
sendPacket
Sends a packet to the server.Will do nothing if
!isConnected().- Parameters:
packet- Packet to send- Throws:
IllegalStateException- IfPacketSerializer.toArray()fails
-
isConnected
public boolean isConnected()Checks if this client is currently connected to the server.- Returns:
- Whether this client is connected
-
getServerAddress
Gets this client's server's address.- Returns:
- Server's address
-
getServerPort
public int getServerPort()Gets this client's server's port.- Returns:
- Server's port
-
getSocket
Gets this client's socket.Will return
nullif!isConnected().- Returns:
- Client's socket
-
getID
Gets this client's ID.Will return
nullif!isConnected().- Returns:
- Client's ID
-
getInput
Gets this client's data input stream.Will return
nullif!isConnected().- Returns:
- Client's input stream
-
getOutput
Gets this client's data output stream.Will return
nullif!isConnected().- Returns:
- Client's output stream
-