Answer the question
In order to leave comments, you need to log in
How to setup network socket in linux?
Hello, I have two computers connected by a switch. One is running the server program (A), the other is the client program (B). Between them, by means of Berkeley sockets, the data transfer protocol is implemented as follows: we read the first four bytes, they contain the length of the message (x) in bytes, we get the length of the message x + 4, then to write the message, fill the first 4 bytes with the value of the remaining length, write. The sizes of the receive-transmit buffers have a fixed size (for simplicity, the maximum message size is not larger than the size of the buffer). Duck here at first, and A and B were on the same computer. and through them back and forth chasing a loop of 16 gigs (programs were not always completed, sometimes they were blocked) and how the server was transferred to another computer. (simulating a real network), much less data began to come and go, then the server on epoll_wait () was blocked.
Yes, I wrote a lot) But for the past week I've been looking for a solution to the problem, namely: "What the hell? The amount of data known to both sides is transmitted through blocked sockets." But they are blocked either on epoll_wait (), then on read / write, then the program is completely executed. I did not expect such behavior, before that I worked with non-blocking sockets with EPOLL (ET), everything flew. Now I think it can add-change socket options both on SOL_SOCKET and IPPROTO_TCP levels. What do you say, do you recommend?
Yes, I’ll also add: in some client requests, for example, if the first 4 bytes contain -1, the server should not respond to the client, but after such “unidirectional” iterations it most often stalls.
The campaign will have to write additions under the numbers:
1) I begin to understand a little. I wrote a prototype of programs with artificial sizes of sent messages in order to know exactly where how much should come and go. The algorithm consists of 8 iterations, in the first, second and third, the client sends messages only 4 bytes each with the value -1, the servet reads -1 with this value it should not respond, the client knows about it, then it sends the maximum buffer size, the server reads and also gives the maximum buffer size, and then there is no point in explaining) It's just that the first three requests were pushed into the kernel buffer and sent to the server as a whole, and the server perceived it as one request. What followed was complete rubbish. So I don’t see any other way out, I’ll have to read, in pieces, first a constant size with a length and then everything else (Is it possible differently?
Answer the question
In order to leave comments, you need to log in
Read Sneijder's textbook on TCP/IP.
In particular, the place where it is written that read (write) can read fewer bytes than it is specified as a parameter.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question