ICMP Checksum error - c++

I am trying to checksum icmp packet using the same technique for tcp and udp but it get wrong checksum, can you tell me where is my problem ?
ICMP_HEADER *icmpheader = new ICMP_HEADER;
memcpy(icmpheader,ICMPHeader,sizeof(ICMP_HEADER));
icmpheader->Checksum = 0;
PSEUDO_HEADER *psheader = new PSEUDO_HEADER;
memcpy(&psheader->daddr, &IPHeader->DestinationAddress, sizeof(UINT));
memcpy(&psheader->saddr, &IPHeader->SourceAddress, sizeof(UINT));
psheader->protocol = IPHeader->Protocol;
psheader->length = htons((USHORT)(sizeof(ICMP_HEADER) + ICMPDataSize));
psheader->zero = 0x0000;
UINT packet_size = sizeof(ICMP_HEADER) + ICMPDataSize + sizeof(PSEUDO_HEADER);
packet_size = packet_size + ((packet_size%2)*2);
UCHAR *icmppacket = (UCHAR*)malloc(packet_size);
memset(icmppacket,0, packet_size);
memcpy(icmppacket, psheader, sizeof(PSEUDO_HEADER));
memcpy(&icmppacket[sizeof(PSEUDO_HEADER)], icmpheader,sizeof(ICMP_HEADER));
memcpy(&icmppacket[sizeof(PSEUDO_HEADER) + sizeof(ICMP_HEADER)],ICMPData,ICMPDataSize);
if (GlobalChecksum((USHORT*)icmppacket,packet_size) != ICMPHeader->Checksum)
{
isMalformed = true;
PacketError = PACKET_ICMP_CHECKSUM;
}
USHORT cPacket::GlobalChecksum(USHORT *buffer, UINT length)
{
register int sum = 0;
USHORT answer = 0;
register USHORT *w = buffer;
register int nleft = length;
while(nleft > 1){
sum += *w++;
nleft -= 2;
}
sum = (sum >> 16) + (sum & 0xFFFF);
sum += (sum >> 16);
answer = ~sum;
return(answer);
}

solved it by removing pseudo header and calculating icmp header and icmp data only
ICMP_HEADER *icmpheader = new ICMP_HEADER;
memcpy(icmpheader,ICMPHeader,sizeof(ICMP_HEADER));
icmpheader->Checksum = 0x0000;
UINT packet_size = sizeof(ICMP_HEADER) + ICMPDataSize;
packet_size = packet_size + ((packet_size%2)*2);
UCHAR *icmppacket = (UCHAR*)malloc(packet_size);
memset(icmppacket,0, packet_size);
memcpy(icmppacket, icmpheader,sizeof(ICMP_HEADER));
memcpy(&icmppacket[sizeof(ICMP_HEADER)],ICMPData,ICMPDataSize);
if (GlobalChecksum((USHORT*)icmppacket,packet_size) != ICMPHeader->Checksum)
{
isMalformed = true;
PacketError = PACKET_ICMP_CHECKSUM;
}

Related

WaveOutWrite doesnt produce any sound... syeteo sinewave?

what is wrong with that following code ?
Compiles and executes fine, but doesnt produce any sound... BTW could anyone point me to how produce stereo left and right sound ?
void audio()
{ WAVEHDR _audioHeader;
HWAVEOUT _audioOut = 0;
WAVEFORMATEX _audioStyle;
_audioStyle.wFormatTag = WAVE_FORMAT_PCM;
_audioStyle.nChannels = 1;
_audioStyle.nSamplesPerSec = 44100;
_audioStyle.nAvgBytesPerSec = 44100 * 2;
_audioStyle.nBlockAlign = 2;
_audioStyle.wBitsPerSample = 16;
_audioStyle.cbSize = 0;
_audioHeader.lpData = new char[44100 * 2];
_audioHeader.dwBufferLength = 44100 * 2;
_audioHeader.dwBytesRecorded = 0;
_audioHeader.dwUser = 0;
_audioHeader.dwFlags = WHDR_BEGINLOOP | WHDR_ENDLOOP;
_audioHeader.dwLoops = 0xFFFF;
_audioHeader.lpNext = NULL;
_audioHeader.reserved = 0;
for(unsigned _x = 0; _x < _audioHeader.dwBufferLength / 2; _x += 2)
{ const
double _byte = 128 + 127 * ::cos(double(_x) * 2.0 * M_PI * double(2400) / double(_audioStyle.nSamplesPerSec));
_audioHeader.lpData[_x + 0] = (char)(_byte);
_audioHeader.lpData[_x + 1] = (char)(_byte);
}
::waveOutOpen(&_audioOut, WAVE_MAPPER, &_audioStyle, NULL, NULL, CALLBACK_NULL);
::waveOutPrepareHeader(&_audioOut, &_audioHeader, sizeof(WAVEHDR));
::waveOutWrite(&_audioOut, &_audioHeader, sizeof(WAVEHDR));
::Beep(1200, 500); ::Sleep(1000); ::Beep(2400, 500);
if(_audioOut != 0)
{ ::waveOutReset(&_audioOut);
::waveOutClose(&_audioOut);
::delete [] _audioHeader.lpData;
}
}
after some research, I found that nBlockAlign has to be computed, wBitsPerSample reduced to 8, and mainly, as waveoutopen requires a pointer to HWAVEOUT, other functions only require the handle….
code became :
{ WAVEHDR _audioHeader;
HWAVEOUT _audioOut = 0;
WAVEFORMATEX _audioStyle;
_audioStyle.wFormatTag = WAVE_FORMAT_PCM;
_audioStyle.nChannels = 2;
_audioStyle.nSamplesPerSec = 44100;
_audioStyle.nAvgBytesPerSec = _audioStyle.nSamplesPerSec * _audioStyle.nChannels;
_audioStyle.wBitsPerSample = 8;
_audioStyle.nBlockAlign = (_audioStyle.wBitsPerSample / 8) * _audioStyle.nChannels;
_audioStyle.cbSize = 0;
_audioHeader.dwBufferLength = _audioStyle.nAvgBytesPerSec;
_audioHeader.lpData = new char[_audioHeader.dwBufferLength];
_audioHeader.dwBytesRecorded = 0;
_audioHeader.dwUser = 0;
_audioHeader.dwFlags = WHDR_BEGINLOOP | WHDR_ENDLOOP;
_audioHeader.dwLoops = 0xFFFF;
_audioHeader.lpNext = NULL;
_audioHeader.reserved = 0;
for(unsigned _x = 0; _x < _audioHeader.dwBufferLength; _x += 2)
{ const
double _byte = ::cos(double(_x) * 2.0 * M_PI * double(2400) / double(_audioStyle.nSamplesPerSec));
if(_x > (_audioHeader.dwBufferLength / 2))
{ _audioHeader.lpData[_x + 0] = (char)(128 + 127 * 0);
_audioHeader.lpData[_x + 1] = (char)(128 + 127 * _byte);
}
else
{ _audioHeader.lpData[_x + 0] = (char)(128 + 127 * _byte);
_audioHeader.lpData[_x + 1] = (char)(128 + 127 * 0);
}
}
if(::waveOutOpen(&_audioOut, WAVE_MAPPER, &_audioStyle, NULL, NULL, CALLBACK_NULL) == 0)
if(::waveOutPrepareHeader(_audioOut, &_audioHeader, sizeof(WAVEHDR)) == 0)
::waveOutWrite(_audioOut, &_audioHeader, sizeof(WAVEHDR));
::Sleep(1000);
if(_audioOut != 0)
{ ::waveOutReset(_audioOut);
::waveOutClose(_audioOut);
::delete [] _audioHeader.lpData;
}
}

When I try to write to wav in c++, it says corrupt file

I am trying to write to wav by taking data from the microphone input, and other headers, and putting that into the wav file. I do that, but it still says corrupted file. One note about the code is that in the struct with the headers, it's not in the correct order. In the WriteToWav function I entered it in the correct order based on the chunk and sub chunks. Here's the code:
struct WavHeaders {
//Fmt
char SubChunk1ID[4];
int SubChunk1Size = 16;
int AudioFormat = 1;
int NumChannels = 2;
int SampleRate = 44100;
int BitsPerSample = 16;
int ByteRate = SampleRate * NumChannels * BitsPerSample / 8;
int BlockAlign = NumChannels * BitsPerSample / 8;
//Data
char SubChunk2ID[4];
int SubChunk2Size = 1 * NumChannels * BitsPerSample / 8;
//RIFF
char ChunkID[4];
int ChunkSize = 4 + (8 + SubChunk1Size) + (8 + SubChunk2Size);
char Format[4];
};
void _AudioReader::AudioReader::AudioToWav() {
WAVEFORMATEX wfx = {};
wfx.wFormatTag = WAVE_FORMAT_PCM; // PCM is standard
wfx.nChannels = 2; // 2 channels = stereo sound
wfx.nSamplesPerSec = 44100; // Samplerate. 44100 Hz
wfx.wBitsPerSample = 16; // 16 bit samples
wfx.nBlockAlign = wfx.wBitsPerSample * wfx.nChannels / 8;
wfx.nAvgBytesPerSec = wfx.nBlockAlign * wfx.nSamplesPerSec;
HWAVEIN wi;
waveInOpen(
&wi,
WAVE_MAPPER,
&wfx,
NULL, NULL,
CALLBACK_NULL | WAVE_FORMAT_DIRECT
);
char buffers[2][44100 * 2 * 2 / 2];
WAVEHDR headers[2] = { {},{} };
for (int i = 0; i < 2; ++i){
headers[i].lpData = buffers[i];
headers[i].dwBufferLength = 44100 * 2 * 2 / 2;
waveInPrepareHeader(wi, &headers[i], sizeof(headers[i]));
waveInAddBuffer(wi, &headers[i], sizeof(headers[i]));
}
//Set Header IDS as char array
WavHeaders Wav_Headers;
Wav_Headers.SubChunk1ID[0] = 'f';
Wav_Headers.SubChunk1ID[1] = 'm';
Wav_Headers.SubChunk1ID[2] = 't';
Wav_Headers.SubChunk1ID[3] = ' ';
Wav_Headers.SubChunk2ID[0] = 'd';
Wav_Headers.SubChunk2ID[1] = 'a';
Wav_Headers.SubChunk2ID[2] = 't';
Wav_Headers.SubChunk2ID[3] = 'a';
Wav_Headers.ChunkID[0] = 'R';
Wav_Headers.ChunkID[1] = 'I';
Wav_Headers.ChunkID[2] = 'F';
Wav_Headers.ChunkID[3] = 'F';
Wav_Headers.Format[0] = 'W';
Wav_Headers.Format[1] = 'A';
Wav_Headers.Format[2] = 'V';
Wav_Headers.Format[3] = 'E';
std::ofstream AudioFile("Audio.wav", std::ios_base::out | std::ios_base::binary);
//Write Headers to audio file
for(int i = 0; i < 4; i++) //RIFF Chunk
AudioFile << Wav_Headers.ChunkID[i];
AudioFile << Wav_Headers.ChunkSize << Wav_Headers.Format;
for (int i = 0; i < 4; i++) //fmt(format) sub-chunk
AudioFile << Wav_Headers.SubChunk1ID[i];
AudioFile <<
Wav_Headers.SubChunk1Size <<
Wav_Headers.AudioFormat <<
Wav_Headers.NumChannels <<
Wav_Headers.SampleRate <<
Wav_Headers.ByteRate <<
Wav_Headers.BlockAlign <<
Wav_Headers.BitsPerSample;
for (int i = 0; i < 4; i++) //Data sub-chunk
AudioFile << Wav_Headers.SubChunk2ID[i];
AudioFile << Wav_Headers.SubChunk2Size;
std::cout << "Started recording! Press escape when you're ready to stop!\n";
waveInStart(wi);
while (!(GetAsyncKeyState(VK_ESCAPE) & 0x8000)) {
for (auto& h : headers) {
if (h.dwFlags & WHDR_DONE) {
AudioFile.write(h.lpData, h.dwBufferLength); //dump audio binary to wav file
h.dwFlags = 0;
h.dwBytesRecorded = 0;
waveInPrepareHeader(wi, &h, sizeof(h));
waveInAddBuffer(wi, &h, sizeof(h));
}
}
}
waveInStop(wi);
for (auto& h : headers){
waveInUnprepareHeader(wi, &h, sizeof(h));
}
waveInClose(wi);
}```
So the issue was that I had to keep in mind formatting and Endianess. Instead of using << or .write, you have to have a precise format for it. A way to write to the file in the correct format is to use the following function I used below, and enter the same WAV headers.
template <typename T>
std::ostream& LittleEndianToFile(std::ostream& file, T value, unsigned size = sizeof(T)) {
for (; size; --size, value >>= 8)
file.put(static_cast <char> (value & 0xFF));
return file;
}
usage: LittleEndianToFile(AudioFile,SampleRate, 4);

visual studio access violation reading location 0xc0000005

I am receiving data in TCP in C++ using Qt library. I store the received packet in a QByteArray, but after reading the whole data, I face this error in debug. At the end, I try to clear the buffer, but I face this problem while trying to clear it too.
Here is my code :
void AvaNPortTester::scoket_readyRead()
{
ui.lineEdit_Sending_Status_->setText("Sent");
ui.lineEdit_Sending_Status_->setStyleSheet("QLineEdit { background: rgb(50, 255, 50); }");
tcpSocket_data_buffer_.append(tcpSocket_->readAll());
//qDebug() << serialport_data_buffer_.size();
//auto ddd = QString::number(tcpSocket_data_buffer_.size());// +" : " + tcpSocket_data_buffer_.toHex();
//ui.lableSocketRead->setText(ddd);
bool read_aain = false;
QByteArray dummy(int(1446), Qt::Initialization::Uninitialized);
int reminded_data = 0;
int dummy_size = 0;
int frame_size = 0;
int l_size = 0;
int total_size_rcvd = tcpSocket_data_buffer_.size();
//int total_size_rcvd_b = total_size_rcvd_b;
int temp = 0;
while (total_size_rcvd != 0)
{
if(total_size_rcvd != 0){
auto packet = tcpSocket_data_buffer_.mid(0, 1446);
auto rem = tcpSocket_data_buffer_.mid(1446);//****1146
tcpSocket_data_buffer_ = rem;
QDataStream streamdata(packet);
uint8_t Sync_Header[3];
auto ss = streamdata.readRawData((char*)&Sync_Header, 3);
uint8_t Total_size[2];
ss = streamdata.readRawData((char*)&Total_size, 2);
int t_size = Total_size[0] * 256 + Total_size[1];
uint8_t Reserved[2];
ss = streamdata.readRawData((char*)&Reserved, 2);
frame_size = t_size - 2;
reminded_data = t_size - 2;
while (frame_size != 0)
{
uint8_t portid;
ss = streamdata.readRawData((char*)&portid, 1);
//ui.lineEdit_FileSize->setText(QString::number(fileSend_2Ser->size()));
uint8_t ProtocolID;
ss = streamdata.readRawData((char*)&ProtocolID, 1);
uint8_t MoreFragmentFlag;
ss = streamdata.readRawData((char*)&MoreFragmentFlag, 1);
uint8_t Seq;
ss = streamdata.readRawData((char*)&Seq, 1);
uint8_t size[2];
ss = streamdata.readRawData((char*)&size, 2);
l_size = size[0] * 256 + size[1];
if (packet_flags.Ser2Eth.packet_started[portid] == false) {
uint8_t DDCMP_Header[14];
ss = streamdata.readRawData((char*)&DDCMP_Header, 14);
packet_flags.Ser2Eth.protocol_payload_size[portid] = DDCMP_Header[7] + 256 * DDCMP_Header[8];
temp = packet_flags.Ser2Eth.protocol_payload_size[portid];
packet_flags.Ser2Eth.packet_started[portid] = true;
}
QByteArray ddcmp_datap(int(l_size), Qt::Initialization::Uninitialized);
streamdata.readRawData(ddcmp_datap.data(), l_size - 14);
if ((pre_more_frag == 0) && (MoreFragmentFlag == 0)) {
packet_flags.Ser2Eth.packet_ended[portid] = true;
packet_flags.Ser2Eth.protocol_payload_size[portid] = l_size;
temp = packet_flags.Ser2Eth.protocol_payload_size[portid];
}
else if ((pre_more_frag == 0) && (MoreFragmentFlag == 1)) {
packet_flags.Ser2Eth.packet_ended[portid] = false;
packet_flags.Ser2Eth.protocol_payload_size[portid] = l_size + 16;
temp = packet_flags.Ser2Eth.protocol_payload_size[portid];
}
else if ((pre_more_frag == 1) && (MoreFragmentFlag == 1)) {
packet_flags.Ser2Eth.packet_ended[portid] = false;
packet_flags.Ser2Eth.protocol_payload_size[portid] = packet_flags.Ser2Eth.protocol_payload_size[portid] + l_size;
temp = packet_flags.Ser2Eth.protocol_payload_size[portid];
}
else if ((pre_more_frag == 1) && (MoreFragmentFlag == 0)) {
packet_flags.Ser2Eth.packet_ended[portid] = true;
packet_flags.Ser2Eth.protocol_payload_size[portid] = packet_flags.Ser2Eth.protocol_payload_size[portid] + l_size;
temp = packet_flags.Ser2Eth.protocol_payload_size[portid];
}
if (MoreFragmentFlag == 1) {
pre_more_frag = 1;
}
else {
pre_more_frag = 0;
}
int ff = 0;
if (packet_flags.Ser2Eth.packet_ended[portid] == true) {
packet_flags.Ser2Eth.packet_started[portid] = false;
packet_flags.Ser2Eth.packet_started[portid] = false;
set_port_id_flag(portid, packet_flags.Ser2Eth.protocol_payload_size[portid], ProtocolID);
pre_more_frag = 0;
}
reminded_data = reminded_data - 6 - l_size;
//ui.lableSocketRead->setText(ddcmp_datap.toHex());
frame_size = frame_size - l_size - 6;
}//end of while (frame_size != 0)
uint8_t sync_footer[3];
streamdata.readRawData((char *)&sync_footer, 3);
dummy_size = 1446 - t_size - 8;
uint8_t dummy_data[1000];
streamdata.readRawData((char *)&dummy_data, dummy_size);
total_size_rcvd = total_size_rcvd - 1446;
if (total_size_rcvd == 0) {
tcpSocket_data_buffer_.clear();
}
} //end of if
}//end of while()
}

Websocket Poco can't receive big data

I downloaded and built Poco project from Poco and run WebsocketServer project in poco-1.7.6\Net\samples\WebSocketServer.
When I worked with small data that is smaller 128 KB (131072 bytes), it work perfectly. But if I work with bigger data (I need to send 20 MB), my data will be cut so server don't receive data enough.
Here is code that I copy in project:
WebSocket ws(request, response);
char *buffer = new char[1000000]; // It just receive 131072 bytes
int flags;
int n;
do
{
n = ws.receiveFrame(buffer, sizeof(buffer), flags);
ws.sendFrame(buffer, tmp.length(), flags);
} while (n > 0 || (flags & WebSocket::FRAME_OP_BITMASK) != WebSocket::FRAME_OP_CLOSE);
delete[] buffer;
Deframe code:
int WebSocketImpl::receiveBytes(void* buffer, int length, int)
{
char header[MAX_HEADER_LENGTH];
int n = receiveNBytes(header, 2);
if (n <= 0)
{
_frameFlags = 0;
return n;
}
poco_assert (n == 2);
Poco::UInt8 lengthByte = static_cast<Poco::UInt8>(header[1]);
int maskOffset = 0;
if (lengthByte & FRAME_FLAG_MASK) maskOffset += 4;
lengthByte &= 0x7f;
if (lengthByte > 0 || maskOffset > 0)
{
if (lengthByte + 2 + maskOffset < MAX_HEADER_LENGTH)
{
n = receiveNBytes(header + 2, lengthByte + maskOffset);
}
else
{
n = receiveNBytes(header + 2, MAX_HEADER_LENGTH - 2);
}
if (n <= 0) throw WebSocketException("Incomplete header received", WebSocket::WS_ERR_INCOMPLETE_FRAME);
n += 2;
}
Poco::MemoryInputStream istr(header, n);
Poco::BinaryReader reader(istr, Poco::BinaryReader::NETWORK_BYTE_ORDER);
Poco::UInt8 flags;
char mask[4];
reader >> flags >> lengthByte;
_frameFlags = flags;
int payloadLength = 0;
int payloadOffset = 2;
if ((lengthByte & 0x7f) == 127)
{
Poco::UInt64 l;
reader >> l;
if (l > length) throw WebSocketException(Poco::format("Insufficient buffer for payload size %Lu", l), WebSocket::WS_ERR_PAYLOAD_TOO_BIG);
payloadLength = static_cast<int>(l);
payloadOffset += 8;
}
else if ((lengthByte & 0x7f) == 126)
{
Poco::UInt16 l;
//lenBuffer = l;
if (l > length) throw WebSocketException(Poco::format("Insufficient buffer for payload size %hu", l), WebSocket::WS_ERR_PAYLOAD_TOO_BIG);
payloadLength = static_cast<int>(l);
payloadOffset += 2;
}
else
{
Poco::UInt8 l = lengthByte & 0x7f;
if (l > length) throw WebSocketException(Poco::format("Insufficient buffer for payload size %u", unsigned(l)), WebSocket::WS_ERR_PAYLOAD_TOO_BIG);
payloadLength = static_cast<int>(l);
}
if (lengthByte & FRAME_FLAG_MASK)
{
reader.readRaw(mask, 4);
payloadOffset += 4;
}
int received = 0;
if (payloadOffset < n)
{
std::memcpy(buffer, header + payloadOffset, n - payloadOffset);
received = n - payloadOffset;
}
if (received < payloadLength)
{
n = receiveNBytes(reinterpret_cast<char*>(buffer) + received, payloadLength - received);
if (n <= 0) throw WebSocketException("Incomplete frame received", WebSocket::WS_ERR_INCOMPLETE_FRAME);
received += n;
}
if (lengthByte & FRAME_FLAG_MASK)
{
char* p = reinterpret_cast<char*>(buffer);
for (int i = 0; i < received; i++)
{
p[i] ^= mask[i % 4];
}
}
return received;
}
Can anyone help me, please!
P/s: Sorry about my English
UPDATE: I just got this problem in Chrome. It work fine with Firefox and Edge
Setting setChunkedTransferEncoding should make it work.
In the code before the response is sent set:
response.setChunkedTransferEncoding(true);

Websocket Server in C++ Error on sending message

I've been developing a C++ websocket server and it's working pretty good, except for one error that I don't understand.
The thing is that I can receive data and perform actions claimed by web browsers, but supposing that the server needs to send back some info, the first time it's sent succesfully, but when I repeat the same request (or another one which needs information back to browser), my server tries to send it (apparently successfully), then by itself sends it again (I don't know why) and then the connection is closed.
here's my code for sending messages:
int CSocketNode::SendMsg(const char opr, const char* cad,int length){
if (socket_conn == INVALID_SOCKET)
return -1;
int pos = 0;
int result = 0;
memset(Buffer_out, 0, BUFFER_SIZE);
if(!webSocket){
//Build header
Buffer_out[pos] = 57; //12345 % 256;
Buffer_out[pos + 1] = 48; //12345 / 256;
length++;
if((length / 256) >= 256){
int divi = length / 256;
Buffer_out[pos + 2] = length % 256;
Buffer_out[pos + 3] = divi % 256;
Buffer_out[pos + 4] = divi / 256;
} else {
Buffer_out[pos + 2] = length % 256;
Buffer_out[pos + 3] = 0;
Buffer_out[pos + 4] = length / 256;
}
Buffer_out[pos + 5] = opr;
pos = 5;
memcpy(Buffer_out + pos + 1, cad, length);
} else {
Buffer_out[pos++] = 0x81;
length++;
if(length <= 125){
Buffer_out[pos++] = length;
} else if(length <= 65535) {
Buffer_out[pos++] = 126;
Buffer_out[pos++] = (length >> 8) & 0xff;
Buffer_out[pos++] = length & 0xff;
} else {
Buffer_out[pos++] = 127;
memset(Buffer_out + pos, 0, 8);
for (int i = 7; i >= 0; i--){
Buffer_out[pos++] = (length >> 8*i) & 0xff;
}
}
Buffer_out[pos++] = opr;
memcpy(Buffer_out + pos, cad, length);
}
printf("0: %d, 1: %d, 2: %d, 3: %d, 4: %d. Pos = %d\n", Buffer_out[0], Buffer_out[1], Buffer_out[2], Buffer_out[3], Buffer_out[4], pos);
printf("%s\n", Buffer_out + pos);
result = SendBytes(Buffer_out, length + pos);
return result;
}
int CSocketNode::SendBytes(char *cad, int length){
//Send it
int err = send(socket_conn, cad, length,0);
if (err == SOCKET_ERROR ){
Error("SendBytes Error");
return -1;
}
return 0;
}
The first part of the IF sentence is for my non web browser clients, which works perfectly.
no matter what size the data frame is, less than 125 or less than 65535, the result is the same.
maybe I'm missing something. Maybe I havve to add and a FIN message at the wnd of the message. but according to the WebSocket Manual, it is the first bit of the message which indicates if it's the or not of multiple messages.
If you can tell me what it is I will be very thankful.
Solved it by myself. For some reason that I cannot guess, the memcpy makes the socket pipe not work correctly.
So I used a for loop to copy the message to the buffer. And solved.