I want to write a simple client that sends a message to a server and receives a response. I’ve got a server that broadcasts the same message to all connected clients and its working when I’m testing it with telnet. When I try doing it using the Erlang shell, gen_tcp:send wont send any messages until I’ve close the socket.
This is what I’m trying to do:
{ok, S} = gen_tcp:connect(IP, Port, []).
gen_tcp:send(S, "Test").
flush().
I can see that the message gets sent when I close the socket by looking at my telnet client.
Erlang version:R14B01 (erts-5.8.2)
Update
hdima commented and said that it might be wrong with how the server extract the messages from the stream. This seems to be the case cause when I tried writing my own server the client seems to work as expected. I’ll try to get the source code of the server. The server is written in Java btw.
The main problem is that there is no Universal Message Format. So your first step is to find what message format the server using. You can’t speak with the server on a different language.
Some message formats can be:
For example if the server understand messages delimited by the line feed character you can send two distinct messages with the following code: