C# client and java server interaction

162 views Asked by At

Hello all I hava a big problem with my client-server interaction, when I send a data from client to server it's work but when I send a data from server to my C# client the data are not recieved.

my code: server:

public void ReceiveData(Socket socket, String command) throws IOException {
    System.out.println("reception");

    String[] dataIn;

    BufferedReader br = new BufferedReader(new InputStreamReader(
            socket.getInputStream()));
    String input = br.readLine();
    System.out.println("receive: " + input);

    dataIn = input.split(" ");
    username = dataIn[1];
    System.out.println(dataIn[0]);
    System.out.println(dataIn[1]);
    System.out.println(dataIn[2]);
}

public void SendData(Socket socket, Object data) throws IOException {
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));

    bw.write((String) data);
    bw.flush();
    bw.close();
    System.out.println("send: " + data);
}

my client code:

public void SendLogin(NetworkStream ns, string command, string username, string password)
{
    StreamWriter sw = new StreamWriter(ns);
    sw.WriteLine(command + " " + username + " " + password);
    sw.Flush();
    sw.Close();
}

public String ReceiveString(NetworkStream ns)
{
    string value = "";
    StreamReader sr = new StreamReader(ns, Encoding.ASCII);
    value = sr.ReadLine();
    ns.Close();
    return value;
}

thanks

0

There are 0 answers