Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Applet-Sockets(Plz help me out)

Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
I want to know following:
I have an applet which has socket listener and socket sender. Here is my code:

import java.awt.*;
import java.lang.*;
import java.applet.*;
import java.util.*;
import java.awt.event.*;
public class K_ClientSocket1 extends Applet implements ActionListener{
public TextArea ta;
private Button send;
private Button rcv;
public String g;
Socket localSocket;
PrintWriter out;
int Port = 11200;
//String IpAddr = "";
int localPort;
//char []buffer = new char[4000];

public void init() {
//create GUI's
Panel p = new Panel();
p.setLayout(new FlowLayout());
ta = new TextArea();
send = new Button("Send Message");
rcv = new Button("Listener");
Panel p1 = new Panel();
p1.setLayout(new FlowLayout());

public void actionPerformed(ActionEvent e) {
if(e.getSource() == send)
//Send Data
try {
localSocket = new Socket(InetAddress.getLocalHost(),Port);
localPort = localSocket.getLocalPort();
String s = "Message:Konica Client";
//Setup data stream in and out of socket
out= new PrintWriter(localSocket.getOutputStream());
//send signature to server
catch(UnknownHostException uh)
System.out.println("Unknown Host Exception");
catch (IOException ioe)
System.out.println("Input/output Exception");
if(e.getSource() == rcv)
ServerSocket echoServer = null;
Socket clientSocket = null;
BufferedReader in;
String g;
int sPort;
sPort = localPort;
echoServer = new ServerSocket(sPort);
clientSocket = echoServer.accept();
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream( )));
// while socket open
while ((in.readLine())!= null)
g = in.readLine();
catch (IOException ioe)
System.out.println("Input/output error");
When I try to send to server, i can able to send. But when i try to listen or receive from the server i am getting following errors:[K_ClientSocket1.init]: cannot access 7689
at com/ms/security/permissions/NetIOPermission.check (
at com/ms/security/PolicyEngine.deepCheck (
at com/ms/security/PolicyEngine.checkPermission (
at com/ms/security/StandardSecurityManager.chk (
at com/ms/security/StandardSecurityManager.checkListen (
at java/net/ServerSocket.<init> (
at java/net/ServerSocket.<init> (
at K_ClientSocket1.init (
at com/ms/applet/AppletPanel.securedCall0 (
at com/ms/applet/AppletPanel.securedCall (
at com/ms/applet/AppletPanel.processSentEvent (
at com/ms/applet/AppletPanel.processSentEvent (
at com/ms/applet/ (
at java/lang/ (
Please let me know,
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok, Angela Jessi
now u r getting these exceptions because the VM of browser have security policy which doesn't let applet to write on the socket
so u have two solutions
either u have to make ur applet signed
to change the security policy of VM
tell me in detail what u actually want
Angela Jessi
Ranch Hand
Posts: 428
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Maaten,
Actually Ihave project. I have to develop client side.I have to open the socket and get the value from Printer and update it in my applet.
So I opened the socket with applet. As you know I am getting above errors. Which is the easiest way to make it either to go for signed applet and to change the security policy of VM
I really appreciate your help,
Thanks again,
Plz let me know
My previous laptop never exploded like that. Read this tiny ad while I sweep up the shards.
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic