"oziris" <oziris.groups@gmail.com> wrote in news:1132735967.644492.234110
@z14g2000cwz.googlegroups.com:
> hello !
>
[quoted text clipped - 6 lines]
>
> where MySocket is a subclass of java.net.Socket.
That looks fine to me. Why do you think it is incorrect?
> - Is there a mean to achieve this without using an encapsulation like
>
> MySocket mySocket = new MySocket(java.net.Socket socket) ?
>
> Thanks.
What are you trying to do here?
Some more information (and code) would be nice.
oziris - 23 Nov 2005 12:58 GMT
I had to write a specific Socket class. So now I would
ServerSocket.accept() returns an instance of this class.
The instruction
MySocket socket = (MySocket)serverSocket.accept();
throws a ClassCastException.
According to a reply to the same message on fr.comp.lang.java, the
means seems to consist in extend SocketImpl and related classes.
-o--
Gordon Beaton - 23 Nov 2005 12:09 GMT
> I had to write a specific Socket class. So now I would
> ServerSocket.accept() returns an instance of this class.
Have you looked at ServerSocket.setSocketFactory()?
/gordon

Signature
[ do not email me copies of your followups ]
g o r d o n + n e w s @ b a l d e r 1 3 . s e
oziris - 23 Nov 2005 13:39 GMT
Here the reply of Fabien Bergeret on fr.comp.lang.java
Alors, faut creer une classe MySocket heritant de SocketImpl, puis
creer
une classe MySocketImplFactory qui implemente SocketImplFactory, et
enfin appeler la methode statique setSocketImplFactory de la classe
Socket.
C'est tout ! :-)
In English
You must create a class MySocket which extends SocketImpl and then a
class MySocketImplFactory which implements SocketImplFactory. And
finally you have to call the static method Socket.setSocketImplFactory.
That's all :-)
Subject closed.
Thanks.
-o--
zero - 23 Nov 2005 16:28 GMT
"oziris" <oziris.groups@gmail.com> wrote in news:1132750729.714005.108840
@g47g2000cwa.googlegroups.com:
> I had to write a specific Socket class. So now I would
> ServerSocket.accept() returns an instance of this class.
[quoted text clipped - 9 lines]
>
> -o--
That's not the same code as what you gave in the original post :-)
This of course fails because serverSocket.accept() returns a Socket, not
MySocket. MySocket is a Socket, but not the other way around. The
SocketFactory method mentioned in the other post could work, or you can do
what you originally said:
MySocket socket = new MySocket(serverSocket.accept());
The SocketFactory way is cleaner, but more typing.