Question

Consider the following line of code mySocket.recv(10000). The socket is valid and connected. I know for...

Consider the following line of code mySocket.recv(10000). The socket is valid and connected. I know for a fact that the data I am waiting for is at least 10000 bytes in size. Nevertheless, the recv() function returns only 1000 bytes. What happened (assuming the socket did not become disconnected)? What should be done about it?


This is the full question. There is no code for it.
0 0
Add a comment Improve this question Transcribed image text
Answer #1
  1. Typically, client server send & receive program is written like this -

send program:

bytesWritten = send(socketFd, buf, bytesToSend, flags);

recieve program:

recvedBytes = Recv(sockFd, readBuf, maxBufSize, flag, flags);

Please note that maxBufSize (in your case is 10000bytes) is the maximum size of the read buffer. It is not the maximum size of the data to read. If the send-program is sending 1000bytes then receive program will receive only 1000.

  1. What can be done about this?

The receiving program should be in the loop to read till it reaches its target size.

Example:

recieve program:

total_bytes_recv = 10000;

while (total_bytes_recv <= 0) {

recvedBytes = Recv(sockFd, readBuf, maxBufSize, flag, flags);

total_bytes_recv = total_bytes_recv – recvedBytes;

            }

       Additional information:

  1. In client-server network program, that data is sent over the packet/datagram. MTU is called maximum transfer unit, it is typically 1400 bytes. This is including transport, IP & ethernet header. So typically, the application will send packet less than 1400 bytes to avoid the IP fragmentation.
  2. If the socket program uses the TCP, then there is no concept like message boundary like in UDP. Recieve program will receive in the stream, that is of any size.
Add a comment
Know the answer?
Add Answer to:
Consider the following line of code mySocket.recv(10000). The socket is valid and connected. I know for...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am confused on how to read valid lines from the input file. I am also...

    I am confused on how to read valid lines from the input file. I am also confused on how to count the averages from these valid input lines to keep running the total from these valid lines. If you could show an example of an input and output file that would be amazing as well. Purpose        Learn how to use Java input/output. Due Date       Per the Course at a Glance. Can be resubmitted. Submissions           In this order: printed copy of...

  • # 3. The following code draws a sample of size $n=30$ from a chi-square distribution with...

    # 3. The following code draws a sample of size $n=30$ from a chi-square distribution with 15 degrees of freedom, and then puts $B=200$ bootstrap samples into a matrix M. After that, the 'apply' function is used to calculate the median of each bootstrap sample, giving a bootstrap sample of 200 medians. "{r} set.seed (117888) data=rchisq(30,15) M=matrix(rep(0,30*200), byrow=T, ncol=30) for (i in 1:200 M[i,]=sample(data, 30, replace=T) bootstrapmedians=apply(M,1,median) (3a) Use the 'var' command to calculate the variance of the bootstrapped medians....

  • Hi so I am currently working on a project for a java class and I am...

    Hi so I am currently working on a project for a java class and I am having trouble with a unit testing portion of the lab. This portion wants us to add three additional tests for three valid arguments and one test for an invalid argument. I tried coding it by myself but I am not well versed in unit testing so I am not sure if it is correct or if the invalid unit test will provide the desired...

  • I know is this posted else where BUT I NEED HELP IMPLEMENTING THE TIME DELAY!!!! I...

    I know is this posted else where BUT I NEED HELP IMPLEMENTING THE TIME DELAY!!!! I need a source comment next to the line that gives the delay so i can compare please. (Concurrency – Semaphores) 1.- In this assignment you will implement a deadlock free variant of the bounded-buffer producer/consumer using jBACI (C - -). C- - is a subset of C + + that allows you to declare semaphores and apply the operations P and V. In the...

  • Edit a C program based on the surface code(which is after the question's instruction.) that will...

    Edit a C program based on the surface code(which is after the question's instruction.) that will implement a customer waiting list that might be used by a restaurant. Use the base code to finish the project. When people want to be seated in the restaurant, they give their name and group size to the host/hostess and then wait until those in front of them have been seated. The program must use a linked list to implement the queue-like data structure....

  • How do I make a line of best fit (regression) with the following data? I am...

    How do I make a line of best fit (regression) with the following data? I am aware of how to make it in Microsoft Excel, but I am having trouble figuring out how to find my x value for making the graph. Y value is absorbance, what do I use for x value to calculate the slope? Tube 0.5 mM sulfide standard (ml) Sulfide amount (umol) Sulfide reagent (ml) 0.0 4.9 0.11 0.00 0.2 FeCl3 dH2O to Absorbance 10ml total...

  • C++ Binary Search Tree question. I heed help with the level 2 question please, as level...

    C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...

  • C++ Binary Search Tree question. I heed help with the level 2 question please, as level...

    C++ Binary Search Tree question. I heed help with the level 2 question please, as level 1 is already completed. I will rate the answer a 100% thumbs up. I really appreciate the help!. Thank you! searching.cpp #include <getopt.h> #include <iostream> #include <sstream> #include <stdlib.h> #include <unistd.h> using namespace std; // global variable for tree operations // use to control tree maintenance operations enum Mode { simple, randomised, avl } mode; // tree type // returns size of tree //...

  • I have to modify a server program and chat program to work as the following instructions...

    I have to modify a server program and chat program to work as the following instructions but I am completely clueless as to where to start. I'd appreciate any help on how to atleast get started. This must be done in java. Diffie-Hellman Two parties use a key agreement protocol to generate identical secret keys for encryption without ever having to transmit the secret key. The protocol works by both parties agreeing on a set of values (a) and (q)....

  • For this assignment, you will write a program to work with Huffman encoding. Huffman code is...

    For this assignment, you will write a program to work with Huffman encoding. Huffman code is an optimal prefix code, which means no code is the prefix of another code. Most of the code is included. You will need to extend the code to complete three additional methods. In particular, code to actually build the Huffman tree is provided. It uses a data file containing the frequency of occurrence of characters. You will write the following three methods in the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT