# Equivelent HTTP.jl code for Python socket implementation

**URL:** https://discourse.julialang.org/t/equivelent-http-jl-code-for-python-socket-implementation/129566
**Category:** General Usage
**Tags:** python, sockets, http
**Created:** [June 2, 2025, 4:52pm UTC](https://discourse.julialang.org/t/equivelent-http-jl-code-for-python-socket-implementation/129566 "2025-06-02T16:52:54Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![AwesomeQuest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/awesomequest/32/38910_2.png) [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)
#### Post date: [June 2, 2025, 4:52pm UTC](https://discourse.julialang.org/t/equivelent-http-jl-code-for-python-socket-implementation/129566/1 "2025-06-02T16:52:54Z")

</div>

I’m trying to emulate a piece of Python code that talks to a http server in Julia but I don’t really understand the python code or how to translate it into equivalent HTTP.jl and Sockets.jl code.

Here’s a very compressed MWE of the python code

```julia
import socket

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
IPAddress = socket.gethostbyname(socket.gethostname())
portNumber = 8083
server.bind((IPAddress, portNumber))
server.listen(1)
client, address = server.accept()
client.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
data = client.recv(65536)
print(data)
output = "HTTP/1.1 200 OK\r\nContent-Length: 2\r\nContent-type: application/json\r\n\r\n{}"
client.send(output.encode('utf-8'))

```

(The real code puts the data-receiver on a loop in a different thread)

I’m mostly wondering what the `setsockopt` and `listen` parts do and what their equivalents are in HTTP.jl and Sockets.jl are?

I’ve tried using `HTTP.serve` with the same IP and port like

```julia
datareceiver = HTTP.serve!(IPAddress, 8083, verbose=true) do req
	@show req
	return HTTP.Response("HTTP/1.1 200 OK\r\nContent-Length: 2\r\nContent-type: application/json\r\n\r\n{}")
end

```

but it doesn’t seem to receive any messages.

---

<div class="post-metadata">

### Author: ![AwesomeQuest](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/awesomequest/32/38910_2.png) [@AwesomeQuest](https://discourse.julialang.org/u/AwesomeQuest)
#### Post date: [June 3, 2025, 9:50am UTC](https://discourse.julialang.org/t/equivelent-http-jl-code-for-python-socket-implementation/129566/2 "2025-06-03T09:50:13Z")

</div>

There was a problem with what I was sending to the server. The code with `HTTP.serve!` does in fact work.
