Posted: Mon Nov 03, 2008 12:08 pm Post subject: Determining if an input has value.
First, i apoligise for the title. didn't know how else to word this. What i want is to be able to check if a network input has a value so what i have is :
publicstaticvoid main (String[] args)throwsException { InetAddress lclAdr = InetAddress.getLocalHost();
System.out.println("Your IP address is " + lclAdr.getHostAddress());
System.out.print("How many clients are connecting : ");
count = Integer.parseInt(input.readLine());
synchronized(ss) { for(int i = 0 ; i < count ; i++) { try {
ss [i] = newServerSocket(5050 + i);
} catch(Exception e) { } } }
synchronized(mySocket) { for(int h = 0 ; h < count ; h++) { try {
mySocket [h] = ss [h].accept();
} catch(Exception e) { }
} }
for(int i = 0 ; i < count ; i++) {
isr [i] = newInputStreamReader(mySocket [i].getInputStream());
} for(int i = 0 ; i < count ; i++) {
pw [i] = newPrintWriter(mySocket [i].getOutputStream(), true);
}
for(int i = 0 ; i < count ; i++) {
br [i] = newBufferedReader(isr [i]);
}
new Read ().setPriority(1);
new Write ().setPriority(2);
for(;;) { new Read ().run();
new Write ().run();
} } }
I need a way to replace the
Quote:
try
{
if ((datavar = br [0].readLine ()) == null)
{
new Read().run();
}
if ((datavar = br [0].readLine ()) != null)
{
// datavar = br [0].readLine ();
message = true;
}
else
{
message = false;
System.out.println (datavar);
new Read ().resume ();
}
if (message == true)
{
new Read ().suspend ();
System.out.println (datavar);
message = false;
new Read ().resume ();
}
else
{
}
}
catch (Exception e)
{
//System.out.println ("No Data To Read");
}
with a simpiler statement that:
a) checks for text over the network
b) if text is present, interrupts user input and prints text, then allows user to continue
c) if text is NOT present, allows user to continue inputting
Thanks in advance.
A\V
Sponsor Sponsor
btiffin
Posted: Mon Nov 03, 2008 8:45 pm Post subject: RE:Determining if an input has value.
A\V; Looks like you are digging in quite nicely.
Umm, what if you separate the user input, text output and network I/O into Threads? Would the problem not disappear?
Given this is Java, I don't think a modular approach like that will make the code overly complex. It could simplify a few things.
Cheers
S_Grimm
Posted: Tue Nov 04, 2008 11:22 am Post subject: Re: Determining if an input has value.
Quote:
Umm, what if you separate the user input, text output and network I/O into Threads?
I thought they were.... That is how i was told to delcare threads. Do you mean make more threads? One to read the user input, one to read the network input. one to write the user input to the network, and one to print the network input?