File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Applets and the fly likes What is wrong here! Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "What is wrong here!" Watch "What is wrong here!" New topic

What is wrong here!

Angela Jessi
Ranch Hand

Joined: Nov 27, 2000
Posts: 428
I wrote on applet which is as follows in which I am trying to use socket to connect to server. In TextField1 whatever i add , i want to write this string to server and want to get response back in string 2.
import java.applet.Applet;
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class MyApplet extends Applet implements ActionListener{
Socket localSocket;
PrintWriter out;
BufferedReader in;
BufferedReader kbdInput;
String s;
String t1,t2;
private Button b;
public void init(){
setLayout(new FlowLayout());
TextField t1 = new TextField(20);
t1.setText("Please Enter the value here");
TextField t2 = new TextField(20);
b = new Button("Connect");
public void actionPerformed(ActionEvent e) {
if(e.getSource() == b)
//Create a socket
try {
localSocket = new Socket("",8192);
//Setup data stream in and out of socket and from KeyBoard
in = new BufferedReader(new InputStreamReader(localSocket.getInputStream()));
out= new PrintWriter(localSocket.getOutputStream());
//While we have a connection
//Read Texfield value
//flush the buffer if not full!
// read incoming string from socket
t2 = in.readLine();
catch(UnknownHostException unc)
System.out.println("Connection why not connected");
catch(IOException ioe)
Please let me know what is wrong here in this code. I can compiled but when I run it, when i entered the value and click the button, i am not getting response in text2.
Thanks in advance,
maateen ashraf
Ranch Hand

Joined: Jan 08, 2001
Posts: 122
security policy doesn't let applet to make a socket on client machine so.
either u have to make ur applet signed or use URL connection to send to server....
using http protocol
I agree. Here's the link:
subject: What is wrong here!
It's not a secret anymore!