S
solomon13000
The code bellow is a server code that will continuesly wait for a
vector object from the client side. There are many clients that will
be connected to the server. Must I use threads to handle the many
clients?. Is it advisable to implement threads and why?
import java.net.*;
import java.util.*;
import java.io.*;
public class GandhiServer2
{
ServerSocket ss;
Socket cs;
Vector ht;
ObjectInputStream ois;
public GandhiServer2()
{
try
{
ss = new ServerSocket(9000);
cs = ss.accept();
while(cs.isConnected() == true)
{
ois = new ObjectInputStream(cs.getInputStream());
ht = (Vector)ois.readObject();
System.out.println(ht);
cs = ss.accept();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new GandhiServer2();
}
}
Regards.
vector object from the client side. There are many clients that will
be connected to the server. Must I use threads to handle the many
clients?. Is it advisable to implement threads and why?
import java.net.*;
import java.util.*;
import java.io.*;
public class GandhiServer2
{
ServerSocket ss;
Socket cs;
Vector ht;
ObjectInputStream ois;
public GandhiServer2()
{
try
{
ss = new ServerSocket(9000);
cs = ss.accept();
while(cs.isConnected() == true)
{
ois = new ObjectInputStream(cs.getInputStream());
ht = (Vector)ois.readObject();
System.out.println(ht);
cs = ss.accept();
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
new GandhiServer2();
}
}
Regards.