| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
- package clientest;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.net.Socket;
- import java.net.UnknownHostException;
- public class Client {
- public Client(){
- try {
- Socket client = new Socket("localhost", 5499);
- Thread test = new Thread(new Runnable() {
- @Override
- public void run() {
- DataInputStream input;
- try {
- input = new DataInputStream(client.getInputStream());
- while(true){
- try {
- System.out.println(input.readUTF());
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- });
- test.start();
- while(true){
- DataOutputStream output = new DataOutputStream(client.getOutputStream());
- output.writeUTF("test123");
- try {
- Thread.sleep(1000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- } catch (UnknownHostException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
|