400 Bad request when communicating over socket

Hey,

I’m developing an android app and I’m about to change my system from a php communication to a socket communication. So on my local network this was working perfectly fine but not on Cloudflare. I’ve tried different http ports now. On my local network and with my IP adress I can choose whatever port I want it works but if I’m redirecting the connection over Cloudflare I’m always getting an ‘400 Bad Request’. The only thing I do is replacing my IP with my domain “fawatcher.de” in the config file. Does anybody knows what to do?

This is what I get from Cloudflare:
I/System.out: HTTP/1.1 400 Bad RequestServer: CloudflareDate: Sat, 08 Jun 2019 00:32:23 GMTContent-Type: text/htmlContent-Length: 171Connection: closeCF-RAY: -400 Bad Request

400 Bad Request


Cloudflare

Here’s a list of available ports. Whichever port you’re using appears to be open. But I believe Cloudflare is picky about HTTP/S over the appropriate port:

Have you made sure WebSockets is enabled in the Network settings section?

1 Like

What exactly does this man? You can only proxy HTTP over Cloudflare, not any custom protocols.

And yes, as @sdayman already pointed out, you are limited in your choice of ports.

1 Like

Hey, thanks for the reply. Yes websockets are enabled and i was trying Port 2052 and 2053 but both ended with 400.

1 Like

It‘s meant that I don‘t communicate over port 433. I‘m using java websockets. I‘m not quite sure if Java uses http.

Java Websockets? Can you provide an example? If you use regular sockets with a custom protocol, you would never get this over Cloudflare.

2 Likes

Sorry I meant *serversocket
You mean a code example?

final ServerSocket serverSocket;
int port = 2052;
serverSocket = new ServerSocket(port);
Thread t1 = new Thread(new NetworkService(pool,serverSocket));

Over this socket I send comma seperated data that’s build up like "1,[email protected],svsvsseveeseshhshrjrhh,1,0,1"

Precisely what I meant. You wont be able to proxy a custom protocol over Cloudflare. Cloudflare only supports HTTP.

1 Like

Oh man. Okay, thats bad. But thank you very much for your help!

For those that are confronted with the same issue:
You can add a subdomain on your coundflare account (e.g. “socket.domainname.com”) and guide it arround Cloudflare. It’s not the best way to to solve this problem, but the easiest.

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