[4534] in java-interest
Re: Socket connection in an applet
daemon@ATHENA.MIT.EDU (Terence Chr Haddock)
Fri Jan 5 10:40:58 1996
Date: Fri, 5 Jan 1996 08:39:18 -0500 (EST)
From: Terence Chr Haddock <haddock@UDel.Edu>
To: trk@bilbo.wipsys.soft.net
cc: jig <java-interest@java.sun.com>
In-Reply-To: <9601051630.AA08491@bilbo.wipsys.soft.net>
> **********
> I am reposting this..
> please help me out..
> **********
> Hi !
Greetings. I think the problem is that Netscape 2.0 beta 3 does
not support sockets. It does send an exception (SecurityAccess or
something similar), but you're trapping it here:
> try {
....
> } catch(Exception e){
> // res2 = new String(e.getMessage());
> // If I uncomment the above, applet not initailized
> // error occurs.
> }
Since the catch exists, it catches the exception, but since
everything else is commented out, it does nothing with the exception.
(BTW, bring up the Java Console when you run your applets, that will show
you what kind of error you get when the applet wasn't initialized).
Try obtaining Netscape 2.0 beta 4, I've been able to use sockets
on it, but only to the same host that the applet exists on. Good luck.
- Terry
>
> I have a trivial applet which has to contact the SMTP
> service on its originating host and do the following:
>
....
>
> Things are going fine when I use appletviewer. When I use
> Netscape ( 2b3 on Solaris 2.4) the applet is not able to
> read any message given by the SMTP server. It finds that
> the first two messages are null.
> I use readLine on the DataOutputStream created using the
> getOutputStream() on the connected socket.
>
> I am not getting any Exceptions..
>
> BTW, if I run it as an application ( after modifying the code
> below) things are quite ok.
>
> Here is the code :
> ================================================
>
> import java.net.*;
> import java.awt.*;
> import java.io.*;
> import java.lang.*;
> import java.applet.*;
>
> class SmtpServ {
>
> Socket smtper;
> DataInputStream readable;
> DataOutputStream writable;
> String out;
>
> public SmtpServ(String host, int port)
> throws IOException
> {
> smtper = new Socket(host, port);
> readable = new DataInputStream(smtper.getInputStream());
> writable = new DataOutputStream(smtper.getOutputStream());
> }
>
> public void ComposeAndWriteMsg(String msg)
> throws IOException
> {
> char buf[] = msg.toCharArray();
> int len = msg.length();
> for(int i =0; i < len ; ++i) {
> writable.write(buf[i]);
> }
> writable.write('\015');
> writable.write('\012');
> writable.flush();
> }
>
> public String[] InitDialog()
> throws IOException
> {
> String results[] = new String[2];
>
> results[0] = readable.readLine();
> ComposeAndWriteMsg(new String("HELO"));
> results[1] = readable.readLine();
> return results;
> }
>
> public String QuitDialog()
> throws IOException
> {
> ComposeAndWriteMsg(new String("QUIT"));
> String result = readable.readLine();
> smtper.close();
> return result;
> }
>
> }
>
> public class netest extends Applet {
>
> SmtpServ a;
> String res1[];
> String res2;
>
> public void init()
> {
> res1 = new String[2];
> res2 = new String();
>
> try {
>
> a = new SmtpServ("bilbo", 25);
>
> res1 = a.InitDialog();
> res2 = a.QuitDialog();
> } catch(Exception e){
> // res2 = new String(e.getMessage());
> // If I uncomment the above, applet not initailized
> // error occurs.
> }
>
> }
>
> public void paint(Graphics g)
> {
> if(res1[0] != null)
> g.drawString(res1[0], 30, 40);
> else
> g.drawString("One is null", 30, 40);
>
> if(res1[1] != null)
> g.drawString(res1[1], 30, 80);
> else
> g.drawString("Two is null", 30, 80);
>
> if(res2 != null)
> g.drawString(res2, 30, 120);
> else
> g.drawString("Three is null", 30, 120);
> }
> }
> ==========
> Netscape shows
>
> One is null
>
> Two is null
>
>
> That's all.. nothing about res2
> ========
>
> I suppose I made a silly mistake somewhere. Can someone tell
> me how to make this work?
>
>
> Thanks in adv..
>
> Cheers
> TRK
>
>
>
>
> -
> This message was sent to the java-interest mailing list
> Info: send 'help' to java-interest-request@java.sun.com
>
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com