Can I please have some help over here with a program,more the algorithm..I can't figure it out all the cases for this problem:
"Mini Seti"
The application has 2 components:
Reception(server) wich generates a random list of string characters(>1000) and sends them for the processing to the client(processing units).
Reciever(client) search in the list of characters a regular expression.
The answer for the client would look like this(total number of apparitions,the context of the apparition.
Example(in the ASCII code):
Server sends the following code(characters from 48 to 122 in ASCII):
ajd73jcl392mx30v;]3p2i4j59d9i3o23j4v0su345imsdf-f4-i35876hl2f
The client for example searches for the expression ".[0-9]." which means anythingnumberanything. Answer should look like this:
(number of aparitions,d73 73j l39 392 92m x30 30v ]3p p2i i4j j59 59d......and so on)
My problem here is that I cannot view all of them because my find() function only gets the list once and doesnt show expressions like: d73 73j cause find function doesnt look back.
Here is the part of the code I need to get it work(the client):
Code:
import java.net.*;
import java.io.*;
import java.util.regex.*;
public class Client {
public static void main(String[] args) throws IOException
{
String adr_server="127.0.0.1";
int PORT=8111;
Socket s1=null;
PrintWriter out=null;
BufferedReader in = null;
String feedback=new String();
try
{
s1 = new Socket(adr_server,PORT);
out=new PrintWriter(s1.getOutputStream(),true);
in=new BufferedReader(new InputStreamReader(s1.getInputStream()));
feedback=in.readLine();
System.out.println("Am primit de la server " +feedback);
Pattern p = Pattern.compile( ".[0-9].");
Matcher m = p.matcher(feedback);
String rasp="";
int i=0;
while(m.find())
{
//System.out.println("am gasit "+m.group());
rasp+=m.group()+" ";
i++;
}
System.out.println("Am gasit asemanari in numar de: " +i);
out.println("("+i+","+rasp+")");
}catch(UnknownHostException e)
{
System.err.println("Serverul nu poate fi gasit "+e);
System.exit(1);
}
finally
{
if(out!=null)
out.close();
if(in!=null)
in.close();
if(s1!=null)
s1.close();
}
}
}