Commit 921b4d0f authored by Simo Vuorinen's avatar Simo Vuorinen
Browse files

Writing 10 to /127.0.0.1 at port 1234

Receiving port numbers.
Trying to receive 0th port number.
Received 0'th port number.
Trying to receive 1th port number.
Received 1'th port number.
Trying to receive 2th port number.
Received 2'th port number.
Trying to receive 3th port number.
Received 3'th port number.
Trying to receive 4th port number.
Received 4'th port number.
Trying to receive 5th port number.
Received 5'th port number.
Trying to receive 6th port number.
Received 6'th port number.
Trying to receive 7th port number.
Received 7'th port number.
Trying to receive 8th port number.
Received 8'th port number.
Trying to receive 9th port number.
Received 9'th port number.
Trying to connect to 1234
Connection to 0'th adder created.
Trying to connect to 1235
Connection to 1'th adder created.
Trying to connect to 1236
Connection to 2'th adder created.
Trying to connect to 1237
Connection to 3'th adder created.
Trying to connect to 1238
Connection to 4'th adder created.
Trying to connect to 1239
Connection to 5'th adder created.
Trying to connect to 1240
Connection to 6'th adder created.
Trying to connect to 1241
Connection to 7'th adder created.
Trying to connect to 1242
Connection to 8'th adder created.
Trying to connect to 1243
Connection to 9'th adder created.
Making test 1 in set 1
Received exception while testing ... aborting.
Exception: java.net.SocketTimeoutException: Read timed out
Connections to calculators closing ...
... thread done.
parent 79126204
......@@ -31,8 +31,9 @@ public class UdpSender extends Thread {
int l = 0;
ArrayList<Integer> vastaanotetutsummat = new ArrayList<Integer>();
ArrayList<Socket> sok = new ArrayList<Socket>();
ArrayList<ServerSocket> sok2 = new ArrayList<ServerSocket>();
boolean yhteys=true;
int f= 0;
if (t == -1) {
return;
......@@ -44,6 +45,7 @@ public class UdpSender extends Thread {
potnumbers[h]=p;
outpStream.writeInt(potnumbers[h]);
outpStream.flush();
} catch (Exception e) {
System.out.print("moi");
return;
......@@ -54,15 +56,29 @@ public class UdpSender extends Thread {
}
}
System.out.print("lol");
KerääSoketit(t,sok,vastaanotetutsummat, l);
for (int i = 0; i <=t; i++){
int p =1234+i;
ServerSocket plab = new ServerSocket(p);
Socket soketi = new Socket();
sok.add(soketi);
sok2.add(plab);
System.out.println(soketi);
System.out.println("1");
}
System.out.println("3");
LaskeLuvut(sok, vastaanotetutsummat , l,sok2);
System.out.println(inpStream.readInt());
while(true){
int f=inpStream.readInt();
f=inpStream.readInt();
if (f==1){
int sum=0;
for (int i=0; i<=vastaanotetutsummat.size(); i++) {
sum=sum+vastaanotetutsummat.get(i);}
for (int j=0; j<vastaanotetutsummat.size(); j++) {
sum=sum+vastaanotetutsummat.get(j);}
outpStream.writeInt(sum);
}else if (f==2){
Collections.sort(vastaanotetutsummat);
......@@ -75,8 +91,34 @@ public class UdpSender extends Thread {
}
}
public static void LaskeLuvut(ArrayList<Socket> s1, ArrayList<Integer> v1 , int l1, ArrayList<ServerSocket> ss) {
try {
for (int i=0; i<=s1.size(); i++) {
int q = 0;
ServerSocket o1= ss.get(i);
Socket o = s1.get(i);
o=o1.accept();
InputStream uusiIS = o.getInputStream();
ObjectInputStream inStream = new ObjectInputStream(uusiIS);
if(inStream.readInt()==0) {
inStream.close();
} else {
q=q+inStream.readInt();
System.out.print(q);
v1.add(i, q);
l1++;
}
}
}catch (Exception e) {
}
}
public static void KerääSoketit(int t, ArrayList<Socket> s, ArrayList<Integer> v, int l) {
try {
......@@ -85,37 +127,25 @@ public class UdpSender extends Thread {
ServerSocket plab = new ServerSocket(p);
Socket soketi = new Socket();
soketi=plab.accept();
System.out.println(soketi);
s.add(soketi);
System.out.println("1");
}
System.out.println("3");
for (int j=0; j<=s.size(); j++){
try {
System.out.println("2");
int q = 0;
InputStream uusiIS = s.get(j).getInputStream();
ObjectInputStream inStream = new ObjectInputStream(uusiIS);
while(inStream.readInt()!=0) {
q=q+inStream.readInt();
System.out.print(q);
v.add(j, q);
l++;
}
}System.out.println("2");
}
catch (Exception e) {
System.out.println("moi");
}
}
System.out.println("3"); }
} catch (Exception e) {
}
}
public static void LueSoketinluvut(ArrayList<Socket> s1, ArrayList<Integer> v1 , int l1) {
for (int i=0; i<=s1.size(); i++){
try {
......@@ -159,6 +189,7 @@ 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++;
......@@ -187,7 +218,20 @@ public class UdpSender extends Thread {
try {
o.writeInt(-1);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
return -1;
}
}
private static int lue2(ObjectInputStream i, ObjectOutputStream o) {
try {
return i.readInt();
} catch (Exception e){
try {
o.writeInt(-1);
} catch (IOException e1) {
e1.printStackTrace();
}
return -1;
......
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