A
ahd292
1) Hi everyone. I am working on a network based project that
implements "Multi Client–Multi Server" scenario. In our design we must
create one Central Server and some Secondary server that respond to
client request. At first C.S runs and then some S.S. Secondary servers
connect (TCP) directly to Central Server. In fact Secondary servers
are clients of C.S. I have created 3 classes for first section:
1) CentralServer 2) Secondary 3)SSHandler
For multithreading I create third class as a worker for handling
communication between C.S and S.S.
In second Section Secondary servers are responsible for processing
client requests. Now they (SS) are act as Server. Each client connect
to one of these S.S (by using of an special algorithm). Like to first
section I have 3 classes for this section:
1)Secondary(this is same class as above) 2)Client 3)ClientHandler
For multithreading I create third class as a worker for handling
communication between Client and S.S.
Now my problem occurs when in Secondary class I have to waiting
simultaneously for client requests for connection and data in way from
C.S socket. This is some of my code of Secondary
public class Secondary {
public Secondary() {
csSocket = new Socket(IP, 1234);
output = new ObjectOutputStream(csSocket.getOutputStream
());
in = new ObjectInputStream(csSocket.getInputStream());
ServerSocket ssSocket = new ServerSocket(port);
while (counter < MAX_CLIENT) {
System.out.println("ss waiting for connection");
Socket connection = ssSocket.accept();
ClientHandler handler = new ClientHandler(this,
connection, "id of client");
handler.start();
clients.add(handler);
counter++;
}
public static void main(String[] args) {
Secondary ss = new Secondary();
}
At this moment I just handle connections from clients and I can't know
how to wait for reading objects received from CS. for example suppose
that C.S write something in its output socket and S.S must read it but
in other hand it must wait in while(true) loop for receive client
connections.
Do I create thread for these two works or another solution?
2) and another question. In my secondaryHandler class I create a
object that is instance of one of my date classes named Book. Each
book has a list of another objects that they are instance of Section
Class. Both of those classes are Serializable More in code:
Book book = new Book("name");
Section s = new Section("name");
book.add(s);;
output.writeobject(book)
now when I print sections of book for test it works and book has
section.
but in client class when I read and cast object to Book there is no
section in it. Why?
implements "Multi Client–Multi Server" scenario. In our design we must
create one Central Server and some Secondary server that respond to
client request. At first C.S runs and then some S.S. Secondary servers
connect (TCP) directly to Central Server. In fact Secondary servers
are clients of C.S. I have created 3 classes for first section:
1) CentralServer 2) Secondary 3)SSHandler
For multithreading I create third class as a worker for handling
communication between C.S and S.S.
In second Section Secondary servers are responsible for processing
client requests. Now they (SS) are act as Server. Each client connect
to one of these S.S (by using of an special algorithm). Like to first
section I have 3 classes for this section:
1)Secondary(this is same class as above) 2)Client 3)ClientHandler
For multithreading I create third class as a worker for handling
communication between Client and S.S.
Now my problem occurs when in Secondary class I have to waiting
simultaneously for client requests for connection and data in way from
C.S socket. This is some of my code of Secondary
public class Secondary {
public Secondary() {
csSocket = new Socket(IP, 1234);
output = new ObjectOutputStream(csSocket.getOutputStream
());
in = new ObjectInputStream(csSocket.getInputStream());
ServerSocket ssSocket = new ServerSocket(port);
while (counter < MAX_CLIENT) {
System.out.println("ss waiting for connection");
Socket connection = ssSocket.accept();
ClientHandler handler = new ClientHandler(this,
connection, "id of client");
handler.start();
clients.add(handler);
counter++;
}
public static void main(String[] args) {
Secondary ss = new Secondary();
}
At this moment I just handle connections from clients and I can't know
how to wait for reading objects received from CS. for example suppose
that C.S write something in its output socket and S.S must read it but
in other hand it must wait in while(true) loop for receive client
connections.
Do I create thread for these two works or another solution?
2) and another question. In my secondaryHandler class I create a
object that is instance of one of my date classes named Book. Each
book has a list of another objects that they are instance of Section
Class. Both of those classes are Serializable More in code:
Book book = new Book("name");
Section s = new Section("name");
book.add(s);;
output.writeobject(book)
now when I print sections of book for test it works and book has
section.
but in client class when I read and cast object to Book there is no
section in it. Why?