I have a big problem.... We have a project on school and work as dou. I write the go server and my partner the java client. I have a problem that if he is sending something like: "Hello World" the golang server split this into "Hello" and "World"
The Java Code:
public class DataController {
public String recieveDataFromServer(Socket socket) throws Exception {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
while (!bufferedReader.ready()) { }
String data = bufferedReader.readLine();
return data;
}
public void sendDataToServer(Socket socket, String data) throws Exception
{
PrintWriter printWriter = new PrintWriter(socket.getOutputStream(), true);
printWriter.println(data);
}
}
The go Code:
func handleRequest(conn net.Conn) {
request := make([]byte, 256)
for {
_, err := conn.Read(request)
if err != nil {
Error.Println(err.Error())
return
}
Info.Println("Message Received: " + string(request))
message := []byte(time.Now().String())
message = append(message, []byte(": ")...)
message = append(message, request...)
broadcast(message)
}
}
The broadcast function just do a conn.Write(msg) for all the connections.
Does anyone know that the problem is?
Edit: I found the problem. Java add after each word a . Then the go server think the message ended. We switch now to c#. its easier and work correct while writing with a bufferedWriter to a socket.