Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2006

Tip: Looking for answers? Try searching our database.

socket

Thread view: 
Patrick Wallingford - 24 Nov 2006 08:36 GMT
Hm, I can seem to compile this in Eclipse, but not in command line tools.
What am I missing?

SSLSocket.java:17: incompatible types
found   : java.net.Socket
required: SSLSocket
      SSLSocket socket =
SSLSocketFactory.getDefault().createSocket(TARGET_HTTPS_SERVER,
TARGET_HTTPS_PORT);

-- code --

import java.io.*;
import java.net.*;
import javax.net.*;
import javax.net.ssl.*;
import java.security.*;
import java.security.cert.Certificate;

 public class SSLTest {

    private SSLSession sslSession = null;

    public static final String TARGET_HTTPS_SERVER = "localhost";
    public static final int    TARGET_HTTPS_PORT   = 8443;

    public static void main(String[] args) throws Exception {

      SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().
        createSocket(TARGET_HTTPS_SERVER, TARGET_HTTPS_PORT);

      SSLSession sslSession = socket.getSession();

      Certificate[] localCerts = null;
      Certificate[] peerCerts = sslSession.getPeerCertificates();

etc...
wesley.hall@gmail.com - 24 Nov 2006 13:55 GMT
> Hm, I can seem to compile this in Eclipse, but not in command line tools.
> What am I missing?

You seem to be compiling two different versions of the source code...
look...

> SSLSocket.java:17: incompatible types
> found   : java.net.Socket
> required: SSLSocket
>        SSLSocket socket =
> SSLSocketFactory.getDefault().createSocket(TARGET_HTTPS_SERVER,
> TARGET_HTTPS_PORT);

Notice how the line here does NOT have the cast to SSLSocket?

> -- code --

>        SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().
>          createSocket(TARGET_HTTPS_SERVER, TARGET_HTTPS_PORT);

Notice how this one does!

The cast is required because createSocket returns a Socket not an
SSLSocket.
Chris Uppal - 24 Nov 2006 14:09 GMT
Error message
> found   : java.net.Socket
> required: SSLSocket
>        SSLSocket socket =
> SSLSocketFactory.getDefault().createSocket(TARGET_HTTPS_SERVER,

Code:
>        SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().
>          createSocket(TARGET_HTTPS_SERVER, TARGET_HTTPS_PORT);

Note that the error message doesn't match the code. The code you posted has an
explicit cast of the returned value from createSocket(), whereas the code the
compiler is moaning about lacks that cast.  So the compiler refuses the
assignment of a Socket reference to a SSLSocket variable.

   -- chris
Patrick Wallingford - 27 Nov 2006 10:59 GMT
Whoa,

My bad. The actual error is, when I do make the cast, it works on Eclipse
but fails on command line compiling giving the following error:

SSLSocket.java:17: inconvertible types
found   : java.net.Socket
required: SSLSocket
      SSLSocket socket = (SSLSocket)
SSLSocketFactory.getDefault().createSocket(TARGET_HTTPS_SERVER,
TARGET_HTTPS_PORT);

---

What could be causing that in the IDE this seems to work? :(

> Error message
>> found   : java.net.Socket
[quoted text clipped - 14 lines]
>
>    -- chris
Chris Uppal - 28 Nov 2006 15:30 GMT
> My bad. The actual error is, when I do make the cast, it works on Eclipse
> but fails on command line compiling giving the following error:
[quoted text clipped - 9 lines]
>
> What could be causing that in the IDE this seems to work? :(

I can't think of anything specific. It /should/ work (the IDE is correct).  It
seem that the problem must be some sort of configuration/classpath issue with
the command-line tools, but I can't guess what from here.

Two things to try:

Execute
   java -version
and
   javac -J-showversion

to check that both commands, "java" and "javac", are actually resolving to the
Java installation that you expect.   If you are using, say, Ant to build, then
you'll have to work harder to find out what's really going on :-(

Try (if you haven't already) being explicit about
   import javax.net.ssl.SSLSocket;
in your Java source, just in case "SSLSocket" is resolving to something weird.
(Since you are using Eclipse, the chances are that you /are/ doing that
already).

Beyond that, I'm afraid, I have no other suggestions.

   -- chris


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.