# Received: "" (no content received) before the code executes

**URL:** https://forum.codecrafters.io/t/received-no-content-received-before-the-code-executes/15396
**Category:** Challenges
**Tags:** challenge:redis
**Created:** [October 13, 2025, 7:43am UTC](https://forum.codecrafters.io/t/received-no-content-received-before-the-code-executes/15396 "2025-10-13T07:43:51Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![sabyasachinayak3001](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/sabyasachinayak3001/32/18502_2.png) [@sabyasachinayak3001](https://forum.codecrafters.io/u/sabyasachinayak3001)
#### Post date: [October 13, 2025, 7:43am UTC](https://forum.codecrafters.io/t/received-no-content-received-before-the-code-executes/15396/1 "2025-10-13T07:43:51Z")

</div>

I’m stuck on Stage #LX4

I’ve tried .. adding print statements, to check why if my code is not running properly, but i am not able to find out why it shows the _Received: “” (no content received)_ in the logs.

Here are my logs:

```auto
[tester::#LX4] Running tests for Stage #LX4 (Lists - Append multiple elements)
[tester::#LX4] $ ./your_program.sh
[tester::#LX4] [client] $ redis-cli RPUSH blueberry mango banana
[tester::#LX4] [client] Sent bytes: "*4\r\n$5\r\nRPUSH\r\n$9\r\nblueberry\r\n$5\r\nmango\r\n$6\r\nbanana\r\n"
[tester::#LX4] Received: "" (no content received)
[tester::#LX4] ^ error
[tester::#LX4] Error: Expected start of a new RESP2 value (either +, -, :, $ or *)
[tester::#LX4] Test failed
[tester::#LX4] Terminating program
[your_program] INPUT COMMAND = RPUSH
[your_program] INSIDE RPUSH
[your_program] LIST ITEM = MANGO
[your_program] LIST ITEM = BANANA
[tester::#LX4] Program terminated successfully

```

And here’s a snippet of my code:

```java
public static void main(String[] args){
        // You can use print statements as follows for debugging, they'll be visible when running tests.
        // System.out.println("Logs from your program will appear here!");
        // Uncomment this block to pass the first stage
        ServerSocket serverSocket = null;
// Socket clientSocket = null;
        int port = 6379;
        try {
            serverSocket = new ServerSocket(port);
            // Since the tester restarts your program quite often, setting SO_REUSEADDR
            // ensures that we don't run into 'Address already in use' errors
            serverSocket.setReuseAddress(true);
            // Wait for connection from client.
// while (true) {
                Socket clientSocket = serverSocket.accept();
                new Thread(() -> handleClientRefactored(clientSocket)).start();
// }
        } catch (IOException e) {
            System.out.println("IOException: " + e.getMessage());
        }
    }

```

static void handleClientRefactored(final Socket clientSocket) {  
try {  
Map\<String, SetObject\> chm = new ConcurrentHashMap\<\>();  
List list = new ArrayList\<\>();

// BufferedReader in = new BufferedReader(new InputStreamReader(inputStream));  
// BufferedWriter out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));

```auto
        while (true) {
            InputStream inputStream = clientSocket.getInputStream();
            String\[\] input = parseInputStream(inputStream);
            System.out.println("INPUT STREAM LENGTH = " + input.length);
            BufferedWriter out = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));
            if(input.length < 2) {
                break;
            }
            System.out.println("INPUT COMMAND = " + input\[2\].toUpperCase());
            if(input\[2\].equalsIgnoreCase("PING")) {
                System.out.println("INSIDE PING");
                clientSocket.getOutputStream().write("+PONG\\r\\n".getBytes());

```

// out.write(“+PONG\r\n”);  
clientSocket.getOutputStream().flush();  
}  
else if(input[2].equalsIgnoreCase(“ECHO”)) {  
System.out.println(“INSIDE ECHO”);  
out.write(input[3] + “\r\n” + input[4] + “\r\n”);  
out.flush();  
}  
else if(input[2].equalsIgnoreCase(“SET”)) {  
System.out.println(“INSIDE SET”);  
String key = input[4];  
String val = input[6];  
SetObject so = new SetObject();  
so.setVal(val);  
if(input.length \< 8) {  
out.write(“+OK\r\n”);  
out.flush();  
chm.put(key, so);  
}  
String expiryFlag = input[8];  
if(expiryFlag.equalsIgnoreCase(“PX”)) {  
String nb4 = input[9];  
String time = input[10];  
long ms = Long.parseLong(time);  
so.setPx(true);  
so.setPxTimeEnd(System.currentTimeMillis()+ms);  
// System.out.println(“PX FLAG: " + ms);  
}  
chm.put(key, so);  
}  
else if(input[2].equalsIgnoreCase(“GET”)) {  
System.out.println(“INSIDE GET”);  
String key = input[4];  
if(chm.get(key) == null) {  
out.write(”$-1\r\n");  
}  
else {  
SetObject val = chm.get(key);  
if(val.isPx()) {  
if(System.currentTimeMillis() \> val.getPxTimeEnd()) {  
chm.remove(key);  
out.write(“$-1\r\n”);  
}  
else {  
out.write(“$” + val.getVal().length() + “\r\n” + chm.get(key).getVal() + “\r\n”);  
}  
}  
else out.write(“$” + val.getVal().length() + “\r\n” + chm.get(key).getVal() + “\r\n”);  
}  
out.flush();  
}  
else if(input[2].equalsIgnoreCase(“RPUSH”)) {  
System.out.println(“INSIDE RPUSH”);  
for(int i=6; i\<input.length; i+=2) {  
System.out.println(“LIST ITEM = " + input[i].toUpperCase());  
list.add(input[i]);  
}  
out.write(”:" + list.size() + “\r\n”);  
out.flush();  
}  
}  
clientSocket.close();  
} catch (IOException e) {  
System.out.println("IOException: " + e.getMessage());  
}  
}

I tried running the command

codecrafters test –previous, not it shows this error for the PING test itself

---

<div class="post-metadata">

### Author: ![sabyasachinayak3001](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/sabyasachinayak3001/32/18502_2.png) [@sabyasachinayak3001](https://forum.codecrafters.io/u/sabyasachinayak3001)
#### Post date: [October 14, 2025, 11:02am UTC](https://forum.codecrafters.io/t/received-no-content-received-before-the-code-executes/15396/5 "2025-10-14T11:02:55Z")

</div>

Apparently it is due to completely reading the InputStream, before sending the output, hence this odd behaviour

---

<div class="post-metadata">

### Author: ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)
#### Post date: [October 19, 2025, 11:03am UTC](https://forum.codecrafters.io/t/received-no-content-received-before-the-code-executes/15396/9 "2025-10-19T11:03:42Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
