blob: 6269550b399463917c8af5aa289d8a2f4afaf02c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
|
package Server;
import java.util.*;
import java.net.*;
import java.io.*;
public class ChatServer
{
public static Scanner reader = new Scanner(System.in);
public static int portNum = 1001;
public static void main(String[] args) throws IOException
{
String phrase;
ServerSocket Service;
try
{
Service = new ServerSocket(portNum);
} catch (IOException e)
{
System.err.println("Failed listening on port " + portNum + " (" + e + ")");
return;
}
Socket Soc = null;
try
{
Soc = Service.accept();
while (true)
{
DataInputStream input = new DataInputStream( Soc.getInputStream() );
//InputStreamReader inputTemp = new InputStreamReader(Soc.getInputStream());
//BufferedReader input = new BufferedReader(inputTemp);
phrase = input.readLine(); // FIXME: more then 1 line
//System.out.println("Acc");
OutputStreamWriter outTemp = new OutputStreamWriter(Soc.getOutputStream());
BufferedWriter output = new BufferedWriter(outTemp);
phrase = "<" + phrase + ">";
System.out.println(phrase);
output.write(phrase, 0, phrase.length());
output.newLine();
output.flush();
//System.out.println("Done");
}
} catch (IOException e)
{
if (Soc != null)
Soc.close();
System.out.println(e);
Service.close();
}
}
}
|