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 2005

Tip: Looking for answers? Try searching our database.

ServerSocket.accept() & Socket subclass

Thread view: 
oziris - 23 Nov 2005 08:52 GMT
hello !

- Why doing that is incorrect ?

--- code ---
ServerSocket serverSocket = new ServerSocket(11000);
MySocket socket = serverSocket.accept();
--- /code ---

where MySocket is a subclass of java.net.Socket.

- Is there a mean to achieve this without using an encapsulation like

MySocket mySocket = new MySocket(java.net.Socket socket) ?

Thanks.

-o--
zero - 23 Nov 2005 12:41 GMT
"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.


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.