Skip to content

Commit

Permalink
bugfixes, comments, cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pReya committed Nov 23, 2016
1 parent a9dcf35 commit 497bac7
Show file tree
Hide file tree
Showing 2 changed files with 244 additions and 119 deletions.
53 changes: 36 additions & 17 deletions src/ftpServer/Server.java
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);
}

}



}
Loading

0 comments on commit 497bac7

Please sign in to comment.