Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package me.julian.serversocket;
- import android.support.annotation.Nullable;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.net.Socket;
- import java.net.*;
- import java.io.*;
- public class Client {
- public Client(String address, int port) {
- Socket socket = null;
- DataInputStream input = null;
- DataOutputStream out = null;
- try {
- socket = new Socket(address, port);
- System.out.println("Connected");
- input = new DataInputStream(System.in);
- out = new DataOutputStream(socket.getOutputStream());
- }
- catch(UnknownHostException u) {
- System.out.println(u);
- }
- catch(IOException i) {
- System.out.println(i);
- }
- String line = "";
- while (!line.equals("close")) {
- try {
- line = input.readLine();
- out.writeUTF(line);
- }
- catch(IOException i) {
- System.out.println(i);
- }
- }
- try {
- input.close();
- out.close();
- socket.close();
- }
- catch(IOException i) {
- System.out.println(i);
- }
- }
- public static void main(String args[]) {
- System.out.println(args);
- Client client = new Client("127.0.0.1", 5000);
- }
- public static void run() {
- Client client = new Client("127.0.0.1", 5000);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement