int main(int _argc, char *_argv[]) { /* Frame f(69, 'A'); cout << f.isValid() << endl; cout << f.getFrameNumber() << endl; cout << f.getData() << endl; */ /* Byte* packet = f.serialize(); Frame a; a.unserialize(packet); cout << a.isValid() << endl; cout << a.getFrameNumber() << endl; cout << a.getData() << endl; */ Ack a(4, 69); cout << a.isValid() << endl; cout << a.getFrameNumber() << endl; cout << a.getAck() << endl; Byte * b = a.serialize(); Ack c; c.unserialize(b); cout << c.isValid() << endl; cout << c.getFrameNumber() << endl; cout << c.getAck() << endl; return 0; }
void* childProcessACK(void *threadid) { // child process // receive ACK/NAK from receiver struct sockaddr_in srcAddr; socklen_t srcLen; printf("masuk thread\n"); char* serializedAck; while (isSocketOpen) { printf("proses\n"); if (recvfrom(sockfd, serializedAck, 4, 0, (struct sockaddr *) &srcAddr, &srcLen) != sizeof(Ack)) error("ERROR: recvfrom() receive buffer with size more than expected.\n"); Ack *ack = new Ack(serializedAck); int i=0; while (i<WINSIZE) { if (window.getFrameBuffer().getElement((window.getFrameBuffer().getHead()+i)%WINSIZE).getNo() == ack->getFrameNo()) break; else i++; } if (ack->getAck()==ACK) { printf("Received ACK for Frame No: %d\n",ack->getFrameNo()); window.setAckTrue((window.getFrameBuffer().getHead()+i)%WINSIZE); received++; } else if (ack->getAck()==NAK) { printf("Received NAK for Frame No: %d\n",ack->getFrameNo()); if (sendto(sockfd, window.getFrameBuffer().getElement(i).getSerialized(), window.getFrameBuffer().getElement(i).getSize(), 0, (const struct sockaddr *) &receiverAddr, sizeof(receiverAddr)) != window.getFrameBuffer().getElement(i).getSize()) error("ERROR: sendto() sent buffer with size more than expected.\n"); printf("Sending frame no. %d: %s\n", window.getFrameBuffer().getElement(i).getNo(), window.getFrameBuffer().getElement(i).getData()); window.setTimeOut(i); } } pthread_exit(NULL); }