Hello people

I have read the data from the socket, but I am having problems parsing it.
The main idea is to split the data into chucks the divider is /r/n (/r/n=13,10), and then pass this data chunks to another procedure which will process the complete commands, but sometimes the server does not send me a complete command
A complete command is known because the data contains the character 13 and 10, so I believe I must store this data in a buffer.
Can you give me hints on how can I implement this.
I hope my problem is clear

Thanks
Posted on 2004-01-27 11:27:42 by maCo
Store buffer, check for complete commands, remove complete commands from buffer, process complete commands.
Posted on 2004-01-27 16:31:02 by comrade
Thank You comrade
This is what I got, maybe it is not the best way to do this, what do you think.
I have not tested the code, because I am at school.
I will search for a delete algo when I get home



.data
szDelimeter db 13,10
.data?
szBuffer[1024]:BYTE
.code

OnRead proc
LOCAL buflen:dword, lpBuffer:dword, index:dword
; append socket buffer to global buffer
invoke ioctlsocket, hsocket, FIONREAD, ADDR buflen
invoke GlobalAlloc, GPTR, buflen
mov lpBuffer, eax
invoke recv, hsocket, eax, buflen, 0
invoke lstrcat, ADDR szBuffer, lpBuffer
invoke GlobalFree, lpBuffer
; try to read complete command
invoke Instring, 1, ADDR szBuffer, ADDR szDelimeter
mov index, eax
.while (index > 0)
invoke GlocalAlloc, GPTR, eax
mov lpBuffer, eax
invoke lstrcpyn, eax, ADDR szBuffer, index
invoke ProcessCommand, lpBuffer
invoke GlobalFree, lpBuffer

; here delete the complete command

invoke Instring, 1, ADDR szBuffer, ADDR szDelimeter
mov index, eax
.endw
OnRead endp
Posted on 2004-02-03 11:01:18 by maCo