what about?

```ruby
s = Integer(sock) rescue 0
```