Skip to content

Instantly share code, notes, and snippets.

@ba0f3
Last active November 6, 2019 00:58
Show Gist options
  • Save ba0f3/cb654ca7fd376b79d59676ff834a908c to your computer and use it in GitHub Desktop.
Save ba0f3/cb654ca7fd376b79d59676ff834a908c to your computer and use it in GitHub Desktop.
var data = file.readFile()
var filedata = splitToChunks(data,24)
echo filedata
for i in filedata:
echo i
client.send(i & "\r\L")
client.send("DONE" & "\r\L")
var data = file.readFile()
var filedata = splitToChunks(data,24)
echo filedata
for i in filedata:
echo i
client.send(i & "\r\L")
client.close()
var data = ""
var output = open("D:\\test.txt",fmWrite)
while data != "DONE":
echo "Receving..."
output.write(data & "\r\L")
data = client.recvLine()
echo "DONE"
const MAX_BUFFER_SIZE = 1024
var buffer: array[MAX_BUFFER_SIZE, char] # pre-allcated buffer
var output = open("D:\\test.txt",fmWrite)
var readLength = server.recv(addr buffer, MAX_BUFFER_SIZE) # server try to read 104 bytes from client, but if client send less, it will return in readLength
while readLength != -1: # if there is no data, or client disconnected, readLength will returns -1
echo "Receving..."
output.writeBuffer(addr buffer, readLength) # write everything it read from client to output file
readLength = server.recv(addr buffer, MAX_BUFFER_SIZE) # continue receiving
server.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment