Commit 559d6371 authored by Simo Vuorinen's avatar Simo Vuorinen
Browse files

Update Pls hjälp!

parent 2ac741da
......@@ -48,33 +48,35 @@ public class UdpSender extends Thread {
}
}
for (int i = 0; i<t; i++) {
int p = 1234+i;
for (int i = 0; i<t; i++) {
int p = 1234+i;
ServerSocket plib = new ServerSocket(p);
plib.setSoTimeout(5000);
Socket so = new Socket();
so = plib.accept();
sok.add(i, so);
System.out.println(sok);
plib.setSoTimeout(5000);
plib.close();
}
for (int k=0; k<t; k++) {
final LaskeLuvut laskuri= new LaskeLuvut(vastaanotetutsummat, k, sok);
laskuri.run();
}
System.out.println(vastaanotetutsummat);
System.out.println("456");
}
for (int r = 0; r<t; r++) {
LaskeLuvut laskuri= new LaskeLuvut(vastaanotetutsummat, r, sok);
laskuri.run();
}
while(yhteys){
System.out.println(inpStream.readInt());
f=inpStream.readInt();
if (f==1){
int sum=0;
for (int j=0; j<vastaanotetutsummat.size(); j++) {
sum=sum+vastaanotetutsummat.get(j);}
System.out.println(sum+"!");
outpStream.writeInt(sum);
}else if (f==2){
Collections.sort(vastaanotetutsummat);
......@@ -89,40 +91,55 @@ public class UdpSender extends Thread {
public static class LaskeLuvut{
private int k;
private int r;
int l=0;
private ArrayList<Integer> vastaanotetutsummat;
//private ArrayList<Integer> vastaanotetutsummat;
private int z=0;
ArrayList<Socket> sok ;
ArrayList<Socket> sok ;
boolean c;
ArrayList<Integer> vastaanotetutsummat;
private Socket soketti;
LaskeLuvut(ArrayList<Integer> vastaanotetutsummat, int k, ArrayList<Socket> sok){
LaskeLuvut(ArrayList<Integer> vastaanotetutsummat, int r, ArrayList<Socket> sok){
this.sok=sok;
this.k=k;
this.r=r;
this.vastaanotetutsummat=vastaanotetutsummat;
}
public void run() {
public void run() {
try {
boolean c = true;
int q = 0;
InputStream uS = sok.get(k).getInputStream();
soketti = sok.get(r);
InputStream uS = soketti.getInputStream();
ObjectInputStream inStream = new ObjectInputStream(uS);
while (c) {
if(inStream.readInt()==0) {
inStream.close();
} else {
q=q+inStream.readInt();
vastaanotetutsummat.add(z, k);
l++;
System.out.println(inStream.readInt());
try {
while (c) {
System.out.println("6");
z=inStream.readInt();
//System.out.println("2");
//c=false;
//inStream.close();
q=q+z;
System.out.println(q);
System.out.println("3");
l=l+1;
System.out.println(l+"moi");
}
}
vastaanotetutsummat.add(q);
}catch (Exception e1) {
e1.printStackTrace();
}
inStream.close();
}catch (Exception e) {
System.out.println("vittu!!!");
e.printStackTrace();
}
}
......@@ -142,7 +159,6 @@ public class UdpSender extends Thread {
soketti = pleb.accept();
pleb.close();
System.out.println("TCP muodostettu");
System.out.println(soketti);
return soketti;
} catch (SocketException e) {
yrityskerta++;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment