Your segment class only contains a pointer to the data. You are only sending that pointer, which is useless to the receiver on a completely different machine.
You can't cast the &seg to a char pointer (unless you have a cast operator) and expect it to work. You're going to be sending the first segment_length bytes starting at the base of seg, which is not where your data is.
The line should be:
buf = seg.getData();
You have a similar problem with the receiver.
memcpy( &mmm, buffer, sizeof(buffer) );
That's going to wipe out segment (and data following segment on the stack) and probably cause a segmentation fault. It's not putting data into segment's data area.
Try this instead:
1 2
i = recvfrom(server_socket, mmm.getData(),max_seg_length, 0, (SOCKADDR *) & SenderAddr, &SenderAddrSize);
edit: Not clear where segment_length comes from. It really should be an attribute of segment.
But I need to send the data in the segment and the seq_no too .... the way you told me is only sending the data of the segment .... Is there is another ideas for making a segment with seq_no ?
I am using protocol GBN (Go Back N) which is using the sequence no. of the segment and a buffer with a window size ... and the receiver sends Ack when a segment is delivered with its sequence number .... this way checks if segments are lost ... and resend it ...