Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

sending files through a Socket after its been closed

807597May 17 2005 — edited Feb 24 2006
OK im writing an FTP server/client and it works great...If the client only downloads one file. Heres the code that sends the file
public void sendFile(String dir, Socket sock2)
	{
		try
		{
			BufferedOutputStream send = new BufferedOutputStream(sock2.getOutputStream());
			try
			{
				File g = new File(dir);
				System.out.println(g.getPath());
				FileInputStream in = new FileInputStream(g);
				int c=0;
				while((c = in.read()) != -1)
				{
					send.write(c);
				}
				send.close();
				System.out.println("File Sent");
			}
			catch (IOException err) {}
		}
		catch (IOException err) {System.out.println(err);}
	}
It sends the first file then closes the socket to complete the transfer (Otherwise file never finishes sendind) then when it gets called again it dosnt reopen the socket. I am now thinking I need to look into supporting mulitple clients. but basicly How to I reopen the Socket to send another File?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 24 2006
Added on May 17 2005
21 comments
274 views