Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package serwer;
- import java.net.*;
- import java.io.*;
- /**
- *
- * @author student
- */
- class Odbieranie extends Thread
- {
- InputStream in;
- Odbieranie(InputStream in)
- {
- this.in=in;
- }
- public void run()
- {
- try
- {
- while(true)
- {
- int k = 0;
- StringBuffer sb = new StringBuffer();
- while((k=in.read())!=-1 && k != '\n' )
- {
- sb.append((char)k);
- }
- String wiadomosc = sb.toString().trim();
- System.out.println(wiadomosc);
- }
- }catch (Exception e){}
- }
- }
- public class Serwer {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- // TODO code application logic here
- try
- {
- ServerSocket serwer = new ServerSocket(4444);
- Socket gniazdo = serwer.accept();
- InputStream in = gniazdo.getInputStream();
- OutputStream out = gniazdo.getOutputStream();
- Odbieranie o1 = new Odbieranie(in);
- o1.start();
- BufferedReader klawiatura = new BufferedReader(new InputStreamReader(System.in));
- while (true)
- {
- String linia = klawiatura.readLine();
- out.write(linia.getBytes());
- out.write("\r\n".getBytes());
- }
- }catch(Exception e){}
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement