-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathServer.java
More file actions
86 lines (55 loc) · 1.42 KB
/
Copy pathServer.java
File metadata and controls
86 lines (55 loc) · 1.42 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import java.io.*;
import java.util.Scanner;
import java.net.*;
class Server{
public static void main(String[] args) {
try{
MyFrame frame=new MyFrame("Server Window");
ServerSocket ss=new ServerSocket(6666);
Socket s=ss.accept();//establishes connection
// frame.setFlag(false);
DataOutputStream dout=new DataOutputStream(s.getOutputStream());
Scanner sc=new Scanner(System.in);
DataInputStream dis=new DataInputStream(s.getInputStream());
String send="";
String Exit="start";
while(!Exit.equals("bye")){
// frame.setFlag(false);
String str=(String)dis.readUTF();
while(!str.equals("over")){
if(str.equals("bye")){
break;
}
// System.out.println("Client send: "+str);
frame.addString(str);
str=(String)dis.readUTF();
}
Exit=str;
if(Exit.equals("bye")){
break;
}
do{
// System.out.print("Write message: ");
// frame.setFlag(true);
send=frame.getString();
int count=0;
while(send.length()==0){
send=frame.getString();
Thread.sleep(100);
if(count>=10)
send="over";
count+=1;
}
if(send.equals("bye")){
break;
}
dout.writeUTF(send);
dout.flush();
}while(!send.equals("over"));
Exit=send;
}
dout.close();
ss.close();
}catch(Exception e){System.out.println(e);}
}
}