Hi.
I'm dealing a small program that has a SocketServer.
I have a specific simple protocol that I'm implementing by myself.
For the server I'm openeing a thread for every new session = socket
(for a user connecting to the server).
The problem is with the protocol design:
I want to have an abstract class for "Message" - a protocol message between the server and
the client.
Tryed to create inside a "Session" class (which identifies each connection = independant socket)
an abstract class for Message, so each session can instantiate new messages for every request (=message).
The problem - something with the generics doesn't seem to work.
These are the relevant headers:
Session.java
-------------------
public class Session <M extends Message> extends Thread {
.
.
public abstract class Message {
public abstract String treatMessage(InetAddress ip, int port);
// Did you ever create InetAddress in Message, or is in any super classes it might have?
// did you define port in Message or superclass?
// is there a way to use polymorphism to make a reference variable of superclass type point to subclass type if needed?
// what are the <> for?
// why is Message being defined inside of Session if it extends it instead of, if anything, Session being defined within Message?
}
.
.
}
Introduce.java
-------------------
public class Introduce extends Message {
// were any parameters overridden from Message and not referenced with super?
// did you have ever define a method called treatMessage in Introduce, with same parameters and everything?
}
inside "Introduce" class I get error messages from eclipse:
"no enclosing instance of type Session<M> is available due to some intermediate constructor invocation."
"Session.Message is a raw type. References to generic type Session<M>. Message should be parametrized."
The design is in this way because all sessions share the same database, and this is the design I found
for this situation (inner class). If any new good idea for design I'd love to hear..
thanks..