Comments (4)
Good point, does not look like the API takes into consideration the use case where we just want call socket.read
and just read everything until the socket is closed.
Can you check if using a regular socket works in the above scenario when calling socket.read
?
If so, I will update the gem to support a read with no parameters.
from net_tcp_client.
Yes, you can call IO#read without any parameters:
If length is omitted or is nil, it reads until EOF and the encoding conversion is applied, if applicable. A string is returned even if EOF is encountered before any data is read.
Here is an example minimal Whois client:
TCPSocket.open("whois.nic.me", 43) do |sock|
sock.write("DOMAIN njh.me\r\n")
response = sock.read
puts "Received: #{response}"
end
It would also be really useful to be able to read line by line (IO#gets / IO#each_line / IO#readlines).
Here is an example minimal HTTP client:
TCPSocket.open("www.bbc.co.uk", 80) do |sock|
sock.write("GET / HTTP/1.0\nHost: www.bbc.co.uk\n\r\n")
sock.each_line do |line|
line.chomp!
break if line.empty?
puts "Header: #{line}"
end
puts "Body: #{sock.read}"
end
It reads headers line by line, until a blank line and then reads the body until EOF.
from net_tcp_client.
Want to submit a pull request adding both capabilities?
from net_tcp_client.
I have taken a quick look and it doesn't look straightforward. While the length parameter for IO#read
is optional, the length parameter for IO#read_nonblock
is not. I am not sure I understand what you are doing in your code well enough to work out how to add support for this.
I was having trouble with IPv6 being down for some public whois server - so I was looking at Net::TCPClient
for use in the whois ruby gem. Hower the author is not keen on adding an external dependency. The problem is probably solved just by iterating over the addresses using Resolv.each_address
.
from net_tcp_client.
Related Issues (8)
- SSL HOT 2
- Net::TCPClient#socket_write corrupts data on short writes HOT 7
- SSL+SNI: Set OpenSSL::SSL::SSLSocket#hostname for shared hosts HOT 1
- send() results in NoMethodError HOT 1
- problem with logger in 1.0.1 version HOT 4
- do you plan to implement SOCKS support? HOT 6
- #closed? and #alive? raise exception if server is closed HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from net_tcp_client.