-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
244 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,65 @@ | ||
package ftpServer; | ||
|
||
import java.io.IOException; | ||
import java.net.ServerSocket; | ||
import java.net.Socket; | ||
|
||
public class Server | ||
{ | ||
private int controlPort = 1025; | ||
private ServerSocket welcomeSocket; | ||
boolean serverRunning = true; | ||
|
||
public Server() | ||
public static void main(String[] args) | ||
{ | ||
// TODO Auto-generated constructor stub | ||
new Server(); | ||
} | ||
|
||
public static void main(String[] args) | ||
public Server() | ||
{ | ||
try | ||
{ | ||
int nPort = 1025; | ||
ServerSocket welcomeSocket = new ServerSocket(nPort); | ||
welcomeSocket = new ServerSocket(controlPort); | ||
} | ||
catch (IOException e) | ||
{ | ||
System.out.println("Could not create server socket"); | ||
System.exit(-1); | ||
} | ||
|
||
System.out.println("FTP Server started listening on port " + controlPort); | ||
|
||
System.out.println("FTP Server started on port " + nPort); | ||
|
||
while (serverRunning) | ||
{ | ||
|
||
while (true) | ||
try | ||
{ | ||
// | ||
// Accept connection and start a new FTPSession object for | ||
// each one. | ||
// | ||
|
||
Socket client = welcomeSocket.accept(); | ||
client.setSoTimeout(60*1000); | ||
Worker w = new Worker(client); | ||
System.out.println("New connection received. Worker was created."); | ||
w.start(); | ||
System.out.println("Connection received, worker started"); | ||
w.join(); | ||
} | ||
catch (IOException e) | ||
{ | ||
System.out.println("Exception encountered on accept"); | ||
e.printStackTrace(); | ||
} | ||
|
||
} | ||
catch (Exception e) | ||
try | ||
{ | ||
welcomeSocket.close(); | ||
System.out.println("Server was stopped"); | ||
|
||
} catch (IOException e) | ||
{ | ||
e.printStackTrace(); | ||
System.out.println("Problem stopping server"); | ||
System.exit(-1); | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
} |
Oops, something went wrong.