Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Connection;
- import java.io.IOException;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.net.InetAddress;
- import java.net.Socket;
- import java.net.UnknownHostException;
- public class BuildConnection {
- private int port;
- private String ip;
- private Socket skt;
- private ObjectOutputStream output;
- private ObjectInputStream input;
- public BuildConnection(String i, int p) {
- this.ip = i;
- this.port = p;
- trytoconnect();
- }
- public void trytoconnect() {
- System.out.println("trying to connect");
- try {
- this.skt = new Socket(InetAddress.getByName(this.ip), this.port);
- System.out.println("verbunden");
- setupStreams();
- } catch (UnknownHostException e) {
- System.out.println("fehler verbinden");
- e.printStackTrace();
- } catch (IOException e) {
- System.out.println("fehler verbinden");
- e.printStackTrace();
- }
- }
- public ObjectOutputStream getOutput() {
- return output;
- }
- public void setOutput(ObjectOutputStream output) {
- this.output = output;
- }
- public ObjectInputStream getInput() {
- return input;
- }
- public void setInput(ObjectInputStream input) {
- this.input = input;
- }
- private void setupStreams() throws IOException{
- this.output = new ObjectOutputStream(this.skt.getOutputStream());
- this.output.flush();
- this.input = new ObjectInputStream(this.skt.getInputStream());
- }
- public int getPort() {
- return port;
- }
- public void setPort(int port) {
- this.port = port;
- }
- public String getIp() {
- return ip;
- }
- public void setIp(String ip) {
- this.ip = ip;
- }
- public Socket getSkt() {
- return skt;
- }
- public void setSkt(Socket skt) {
- this.skt = skt;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement