On Mon, 07 Sep 2009 05:27:10 +0900, Bigmac Turdsplash wrote:
im sending files back and forth form a client and a server using
sockets,
the first string the server sends to the client is the size of the file,
"59023"
the client recives this string in this format "59023\n", nil
i need to trim \n and nil from the string so i can do some math with the
string...
--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/
I had it figured out a few minutes after this post... i didnt know the
differnce between a string and array... i convert the array to a string
then used compact
i thought i was working the string class so i was reading threw the
wrong page...
any ways... because of this premature post, i spent a few hours try to
solve a new problem before i ask for help...
strings="a9digh0t5"
# every 3 bytes i need broke into separate strings
puts(string[1]) #==> a9d
puts(string[2]) #==> ihg
puts(string[3]) #==> 0t5
how can i brake a long string into blocks equal to 3 bytes?
--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/
#server.rb
require 'socket' # Get sockets from stdlib
server = TCPServer.open(2000) # Socket to listen on port 2000
loop { # Servers run forever
Thread.start(server.accept) do |client|
file = File.new('/pentest/windows-binaries/tools/test.exe')
fileContent = file.read # reads the file
client.puts(fileContent)
client.close
end
}
#client
require 'socket'
host = '192.168.1.4'
port = 2000
sock = TCPSocket.open(host, port)
data = sock.recvfrom(999999)
destFile = File.open('/tmp/poop.exe', 'wb')
destFile.print data
destFile.close
Ok, just to show you what im working with... it works, but there is a
file size limit when working with recvfrom()
im trying to work out a function to check file size then brake the data
into blocks...
I had it figured out a few minutes after this post... i didnt know the
differnce between a string and array... i convert the array to a string
then used compact
Ridiculous. You would never compact an array just to get the first
element. If you want the first element, then grab it. See Bertram's
posts.
i thought i was working the string class so i was reading threw the
wrong page...
any ways... because of this premature post, i spent a few hours try to
solve a new problem before i ask for help...
strings="a9digh0t5"
# every 3 bytes i need broke into separate strings
puts(string[1]) #==> a9d
puts(string[2]) #==> ihg
puts(string[3]) #==> 0t5
how can i brake a long string into blocks equal to 3 bytes?
If the length of the string will always be a multiple of 3, you can do
this:
str = "a9digh0t5"
str.scan(/.{3}/) do |substr|
puts substr
end
--output:--
a9d
igh
0t5
Otherwise, you'll have to deal with ruby's infernal each_byte() method.
I think 7stud is being sarcastic... He thinks the compact is
unnecessary, and is explaining his point by introducing other
unnecessary elements like inject.
···
On Tue, Sep 8, 2009 at 1:08 AM, Ken Bloom<kbloom@gmail.com> wrote:
On Tue, 08 Sep 2009 03:50:24 +0900, 7stud -- wrote:
Ken Bloom wrote:
On Mon, 07 Sep 2009 05:27:10 +0900, Bigmac Turdsplash wrote:
im sending files back and forth form a client and a server using
sockets,
the first string the server sends to the client is the size of the
file, "59023"
the client recives this string in this format "59023\n", nil
i need to trim \n and nil from the string so i can do some math with
the string...
No, that's not quite the same at all. (I did exactly what he asked for in
the subject line.)
--
Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/
I had it figured out a few minutes after this post... i didnt know the
differnce between a string and array... i convert the array to a string
then used compact
Ridiculous. You would never compact an array just to get the first
element. If you want the first element, then grab it. See Bertram's
posts.
i thought i was working the string class so i was reading threw the
wrong page...
any ways... because of this premature post, i spent a few hours try to
solve a new problem before i ask for help...
strings="a9digh0t5"
# every 3 bytes i need broke into separate strings
puts(string[1]) #==> a9d
puts(string[2]) #==> ihg
puts(string[3]) #==> 0t5
how can i brake a long string into blocks equal to 3 bytes?
If the length of the string will always be a multiple of 3, you can do
this:
str = "a9digh0t5"
str.scan(/.{3}/) do |substr|
puts substr
end
--output:--
a9d
igh
0t5
Otherwise, you'll have to deal with ruby's infernal each_byte() method.
Actually, you can take advantage of a regex's greedy nature, and do this
instead: