-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathServerThread.java
More file actions
39 lines (37 loc) · 1017 Bytes
/
ServerThread.java
File metadata and controls
39 lines (37 loc) · 1017 Bytes
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
/**
* Listens for one connection to the selected port, then stops listening and starts the MainThread.
*
* @author (your name)
* @version (a version number or a date)
*/
import java.net.*;
public class ServerThread extends Thread
{
public Socket mainSocket;
public ServerSocket sock;
public ServerThreadListener listener;
public String password;
public ServerThread(int port, String password){
this.password=password;
try{
sock=new ServerSocket(port);
}
catch(Exception e){
System.out.println("port creation" + e);
}
}
public void run(){
System.out.println("ServerThread start");
try{
mainSocket=sock.accept();
sock.close();
if(listener!=null){
listener.serverConnection();
}
new MainThread(mainSocket, password).start();
}
catch(Exception e){
System.err.println("Listening for connection fail!" + e);
}
}
}