# PNGFiles load from stream doesn't work with TCPSocket

**URL:** https://discourse.julialang.org/t/pngfiles-load-from-stream-doesnt-work-with-tcpsocket/77713
**Category:** General Usage
**Created:** [March 10, 2022, 7:08pm UTC](https://discourse.julialang.org/t/pngfiles-load-from-stream-doesnt-work-with-tcpsocket/77713 "2022-03-10T19:08:44Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![joeynelson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/joeynelson/32/16684_2.png) [@joeynelson](https://discourse.julialang.org/u/joeynelson)
#### Post date: [March 10, 2022, 7:08pm UTC](https://discourse.julialang.org/t/pngfiles-load-from-stream-doesnt-work-with-tcpsocket/77713/1 "2022-03-10T19:08:44Z")

</div>

I have a simple server that just serves up a raw PNG file any client that connects. In Julia I wrote the following function to attempt to load that image.

```julia
function ReadTeensyImage(server)
    sock = Sockets.connect(server,555)
    img = load(sock)
    close(sock)
    return img
end

```

Unfortunately I get the error below. Ideally I would think the PNG library should default to assuming that the `IO` object passed in has no lock function. But it appear to do the opposite. It assumes the object has a lock function unless it is a specific type that does not.

Is there some way I can wrap the TCPSocket in a IOStream to work around this?

```julia
Errors encountered while load Stream{DataFormat{:PNG}, TCPSocket, Nothing}(TCPSocket(Base.Libc.WindowsRawSocket(0x0000000000003160) open, 1214 bytes waiting), nothing).
All errors:
===========================================
MethodError: no method matching lock(::PNGFiles.var"#4#5"{Nothing, Bool, Bool, TCPSocket, Ptr{Nothing}, Ptr{Nothing}}, ::TCPSocket)
Closest candidates are:
  lock(::Any, ::Base.GenericCondition) at C:\Users\joey\AppData\Local\Programs\Julia-1.7.2\share\julia\base\condition.jl:78
  lock(::Any, ::Base.AbstractLock) at C:\Users\joey\AppData\Local\Programs\Julia-1.7.2\share\julia\base\lock.jl:187
  lock(::Any, ::Channel) at C:\Users\joey\AppData\Local\Programs\Julia-1.7.2\share\julia\base\channels.jl:425
  ...
===========================================
MethodError: no method matching fd(::TCPSocket)
Closest candidates are:
  fd(::IOStream) at C:\Users\joey\AppData\Local\Programs\Julia-1.7.2\share\julia\base\iostream.jl:55
  fd(::Base.Filesystem.File) at C:\Users\joey\AppData\Local\Programs\Julia-1.7.2\share\julia\base\filesystem.jl:264
===========================================

Fatal error:
ERROR: MethodError: no method matching lock(::PNGFiles.var"#4#5"{Nothing, Bool, Bool, TCPSocket, Ptr{Nothing}, Ptr{Nothing}}, ::TCPSocket)
Closest candidates are:
  lock(::Any, ::Base.GenericCondition) at C:\Users\joey\AppData\Local\Programs\Julia-1.7.2\share\julia\base\condition.jl:78
  lock(::Any, ::Base.AbstractLock) at C:\Users\joey\AppData\Local\Programs\Julia-1.7.2\share\julia\base\lock.jl:187
  lock(::Any, ::Channel) at C:\Users\joey\AppData\Local\Programs\Julia-1.7.2\share\julia\base\channels.jl:425
  ...

```
