This commit is contained in:
27
app/src/main/java/network/Connexion.java
Normal file
27
app/src/main/java/network/Connexion.java
Normal file
@@ -0,0 +1,27 @@
|
||||
package network;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectOutputStream;
|
||||
import java.net.Socket;
|
||||
|
||||
public abstract class Connexion implements PacketVisitor {
|
||||
|
||||
final Socket socket;
|
||||
private final ObjectOutputStream objectOutputStream;
|
||||
private final ConnexionThread connexionThread;
|
||||
|
||||
public Connexion(Socket socket) throws IOException {
|
||||
this.socket = socket;
|
||||
this.objectOutputStream = new ObjectOutputStream(this.socket.getOutputStream());
|
||||
this.connexionThread = new ConnexionThread(this);
|
||||
this.connexionThread.start();
|
||||
}
|
||||
|
||||
public void sendPacket(Packet packet) throws IOException {
|
||||
objectOutputStream.writeObject(packet);
|
||||
}
|
||||
|
||||
public void close() {
|
||||
this.connexionThread.cancel();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user