Skip to content

Commit d8cd95a

Browse files
committed
Also bei mir funktioniert es ^^
1 parent 215e3b1 commit d8cd95a

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

rn3/src/filecopy/FileCopyClient.java

+15-16
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.net.DatagramPacket;
1212
import java.net.DatagramSocket;
1313
import java.net.InetAddress;
14+
import java.util.Collections;
1415
import java.util.HashMap;
1516
import java.util.Map;
1617
import java.util.concurrent.TimeUnit;
@@ -43,11 +44,13 @@ public class FileCopyClient extends Thread {
4344

4445
FileInputStream inputstream;
4546

46-
Map<Integer, FCpacket> sendbuffer;
47+
static Map<Long, FCpacket> sendbuffer;
4748

4849
FCpacket pinit;
4950

5051
static DatagramSocket clientSocket;
52+
53+
long sendbase = 0;
5154
// ... ToDo
5255

5356
// Constructor
@@ -61,12 +64,10 @@ public FileCopyClient(String serverArg, String sourcePathArg, String destPathArg
6164

6265
}
6366

64-
public void runFileCopyClient() throws IOException, InterruptedException {
67+
public void runFileCopyClient() throws IOException {
6568
inputstream = new FileInputStream(sourcePath);
66-
sendbuffer = new HashMap<Integer, FCpacket>();
67-
// clientSocket = new DatagramSocket();
68-
int sendbase = 0;
69-
int nextSeqNum = 1;
69+
// clientSocket = new DatagramSocket();
70+
long nextSeqNum = 1;
7071
byte[] buf = new byte[1000];
7172

7273
pinit = makeControlPacket();
@@ -76,9 +77,7 @@ public void runFileCopyClient() throws IOException, InterruptedException {
7677
SERVER_PORT);
7778
clientSocket.send(packet);
7879
while (true) {
79-
TimeUnit.SECONDS.sleep(1);
80-
while (inputstream.available() != 0 && sendbuffer.size() <= windowSize) {
81-
System.out.println(sendbuffer.size());
80+
while (inputstream.available() != 0 && sendbuffer.size() < windowSize) {
8281
inputstream.read(buf);
8382
pinit = new FCpacket(nextSeqNum, buf, buf.length);
8483
packet = new DatagramPacket(pinit.getSeqNumBytesAndData(), pinit.getLen() + 8, address, SERVER_PORT);
@@ -153,30 +152,30 @@ public void testOut(String out) {
153152
public static void main(String argv[]) throws Exception {
154153
FileCopyClient myClient = new FileCopyClient(argv[0], argv[1], argv[2], argv[3], argv[4]);
155154
clientSocket = new DatagramSocket();
155+
sendbuffer = new HashMap<Long, FCpacket>();
156156
(new FileCopyClient(argv[0], argv[1], argv[2], argv[3], argv[4])).start();
157157
myClient.runFileCopyClient();
158158
}
159159

160160
@Override
161161
public void run() {
162162
try {
163-
System.out.println("Hello from Thread.");
164163
byte[] data = new byte[FileCopyClient.UDP_PACKET_SIZE];
165164
while (true) {
166165
DatagramPacket udpReceivePacket = new DatagramPacket(data, data.length);
167166
// Wait for data packet
168-
System.out.println(clientSocket.getLocalPort());
169167
clientSocket.receive(udpReceivePacket);
170-
System.out.println("testing");
171-
FCpacket ackpack = new FCpacket(udpReceivePacket.getData(), udpReceivePacket.getLength());
172-
long receivedSeqNumber = ackpack.getSeqNum();
168+
FCpacket ackpack = new FCpacket(udpReceivePacket.getData(), udpReceivePacket.getLength());
169+
long receivedSeqNumber = ackpack.getSeqNum();
173170
if (sendbuffer.containsKey(receivedSeqNumber)) {
174171
sendbuffer.remove(receivedSeqNumber);
172+
// if(sendbuffer.size() >= 0)
173+
// sendbase = Collections.min(sendbuffer.keySet());
174+
System.out.println(sendbase);
175175
}
176-
sleep(1);
177176
}
178177
} catch (Exception e) {
179-
178+
System.out.println(e);
180179
}
181180
}
182181
}

rn3/src/filecopy/FileCopyServer.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void runFileCopyServer() throws IOException {
6767
// Wait for data packet
6868
serverSocket.receive(udpReceivePacket);
6969
receivedIPAddress = udpReceivePacket.getAddress();
70-
System.out.println(receivedPort = udpReceivePacket.getPort());
70+
receivedPort = udpReceivePacket.getPort();
7171

7272
if (connectionEstablished == false) {
7373
// Establish new connection

0 commit comments

Comments
 (0)