Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.io.*;
- import java.net.Socket;
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class EchoThread extends Thread {
- protected Socket socket;
- public EchoThread(Socket clientSocket) {
- this.socket = clientSocket;
- }
- public void run() {
- InputStream inp = null;
- BufferedReader brinp = null;
- DataOutputStream out = null;
- try {
- inp = socket.getInputStream();
- brinp = new BufferedReader(new InputStreamReader(inp));
- out = new DataOutputStream(socket.getOutputStream());
- } catch (IOException e) {
- return;
- }
- String line;
- while (true) {
- try {
- String playerName = "";
- out.writeBytes("WERBIMSTDU\n\r");
- out.flush();
- line = brinp.readLine();
- Pattern ibimsPattern = Pattern.compile("^IBIMS#.+");
- Matcher ibimsMatcher = ibimsPattern.matcher(line);
- if(ibimsMatcher.matches()) {
- playerName = line.substring(6);
- out.writeBytes("HALLO#" + playerName + "\n\r");
- out.flush();
- } else {
- out.writeBytes("Du bimst 1 Lauch.\n\r");
- }
- //out.writeBytes("Server sagt: " + line + "\n\r");
- //out.flush();
- } catch (IOException e) {
- e.printStackTrace();
- return;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement