Answer the question
In order to leave comments, you need to log in
How to bypass the limit on the size of transmitted packets in the network?
Actually there are 2 applications - the client and the server.
The client sends text of arbitrary length to the server, but the server only accepts 1460 characters.
Send code:
IPEndPoint EndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7000);
Socket Connector = new Socket(EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
Connector.Connect(EndPoint);
Byte[] SendBytes = Encoding.Default.GetBytes(Message);
Connector.Send(SendBytes);
Connector.Close();
//Пришло сообщение
ReceiveSocket = Listen.AcceptSocket();
Byte[] Receive = new Byte[256];
//Читать сообщение будем в поток
using (MemoryStream MessageR = new MemoryStream())
{
//Количество считанных байт
Int32 ReceivedBytes;
do
{//Собственно читаем
ReceivedBytes = ReceiveSocket.Receive(Receive, Receive.Length, 0);
//и записываем в поток
MessageR.Write(Receive, 0, ReceivedBytes);
//Читаем до тех пор, пока в очереди не останется данных
} while (ReceiveSocket.Available > 0);
Debug.WriteLine("Received: " + Encoding.Default.GetString(MessageR.ToArray()));
}
Answer the question
In order to leave comments, you need to log in
Socket::Send returns the amount of data actually sent. On the sending side, you need a loop that checks if everything that was passed to Send has been sent and repeats the send for the remaining data.
The receiving side code also needs to be improved, since ReceiveSocket.Available tells how much data is available to receive at the moment, and not how much was sent from the other side.
In a good way, the transmitting and receiving sides should implement the same state machine, and the data stream should contain a protocol that allows the receiving side to synchronize the state of its automaton with the state of the transmitting side machine. These can be fixed-size messages, string interface (like HTTP), TLV, ASN.1, ...
1460 octets is the typical payload size in a single ethernet frame containing a TCP/IP segment.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question