• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

problems in FTP socket in an applet

 
Manimala Kumar
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everybody,
I'm doing a project on mail client system. For remote users i need a ftp of the required file. I am running BRS WebWeaver in my pc and if I try from other pc's with anonymous ftp(i.e. ftp 10.101.1.96 etc.),then it works. But as soon as I try it with my socket initially it flashes a ready message and after that it automatically gets disconnected. So I'm unable to send further commands.
If anybody knows it, please help me. I'm appending my progs here.
Manimala.

//applet code
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import javax.swing.*;
public class japp extends Applet implements ActionListener
{
String attach = null;
Socket localSocket;
PrintWriter outbnd;
BufferedReader inbnd;
String s;
private Button b;
String line = null;
private TextField t2;
public void init()
{
setLayout(new FlowLayout());
attach = getParameter("c"); //get file name with full path from prev text box
t2 = new TextField(60);
add(t2);
b = new Button("Connect");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == b) //Create a socket
try
{
t2.setText(attach);
localSocket = new Socket("10.101.1.96",21); //Setup data
inbnd = new BufferedReader(new InputStreamReader (localSocket.getInputStream()));
outbnd= new PrintWriter(localSocket.getOutputStream());
//While we have a connection
//Read Texfield value
// read incoming string from socket
line = inbnd.readLine();
t2.setText(line);
outbnd.println("anonymous");
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("mani@lycos.com");
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("get "+attach);
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("bye ");
outbnd.flush();
outbnd.close();
inbnd.close();
localSocket .close();
}
catch(UnknownHostException unc)
{
System.out.println("Connection why not connected");
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
}
public static void main( String[] args )//without/with it's ok
{
netappsock applet = new netappsock();
JFrame frame = new JFrame();
frame.setTitle( "Socket Test" );
frame.getContentPane().add( applet , BorderLayout.CENTER );
applet.init();
applet.start();
frame.setSize( 460 , 360 );
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation( ( d.width - frame.getSize().width ) / 2 ,( d.height - frame.getSize().height ) / 2 );
frame.setVisible( true );
}

}

//html code
<html>
<head></head>
<body>
<applet code=japp.class height=400 width=600>
<param name="c" value="C:\jdk1.3\bin\abcd.txt">
</applet>
</body>
</html>


------------------
 
prashant pachouri
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If u are ready to do some change why not try serialized object communication. Read the file contents into a String. Open a socket connection, contruct an objectoutput stream and write the object to it.

Originally posted by Manimala Kumar:
Hello everybody,
I'm doing a project on mail client system. For remote users i need a ftp of the required file. I am running BRS WebWeaver in my pc and if I try from other pc's with anonymous ftp(i.e. ftp 10.101.1.96 etc.),then it works. But as soon as I try it with my socket initially it flashes a ready message and after that it automatically gets disconnected. So I'm unable to send further commands.
If anybody knows it, please help me. I'm appending my progs here.
Manimala.

//applet code
import java.applet.*;
import java.awt.*;
import java.io.*;
import java.awt.event.*;
import java.util.*;
import java.net.*;
import javax.swing.*;
public class japp extends Applet implements ActionListener
{
String attach = null;
Socket localSocket;
PrintWriter outbnd;
BufferedReader inbnd;
String s;
private Button b;
String line = null;
private TextField t2;
public void init()
{
setLayout(new FlowLayout());
attach = getParameter("c"); //get file name with full path from prev text box
t2 = new TextField(60);
add(t2);
b = new Button("Connect");
b.addActionListener(this);
add(b);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource() == b) //Create a socket
try
{
t2.setText(attach);
localSocket = new Socket("10.101.1.96",21); //Setup data
inbnd = new BufferedReader(new InputStreamReader (localSocket.getInputStream()));
outbnd= new PrintWriter(localSocket.getOutputStream());
//While we have a connection
//Read Texfield value
// read incoming string from socket
line = inbnd.readLine();
t2.setText(line);
outbnd.println("anonymous");
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("mani@lycos.com");
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("get "+attach);
outbnd.flush();
line = inbnd.readLine();
t2.setText(line);
outbnd.println("bye ");
outbnd.flush();
outbnd.close();
inbnd.close();
localSocket .close();
}
catch(UnknownHostException unc)
{
System.out.println("Connection why not connected");
}
catch(IOException ioe)
{
System.out.println(ioe.getMessage());
}
}
public static void main( String[] args )//without/with it's ok
{
netappsock applet = new netappsock();
JFrame frame = new JFrame();
frame.setTitle( "Socket Test" );
frame.getContentPane().add( applet , BorderLayout.CENTER );
applet.init();
applet.start();
frame.setSize( 460 , 360 );
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation( ( d.width - frame.getSize().width ) / 2 ,( d.height - frame.getSize().height ) / 2 );
frame.setVisible( true );
}

}

//html code
<html>
<head></head>
<body>
<applet code=japp.class height=400 width=600>
<param name="c" value="C:\jdk1.3\bin\abcd.txt">
</applet>
</body>
</html>


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic