Java(client) and C#(Server) TCP Socket. and Server read infinite last data from client(Java)
I has been search for entire day already, its weird.

I created 2 client: Java(real), C#(for testing)
like this:

Java(Real):

```
Socket socket = new Socket(SyncActivity.ip,SyncActivity.port);
DataOutputStream out;
out = new DataOutputStream(socket.getOutputStream());
String s = "Hello!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!$";
out.write(s.getBytes(),0,s.getBytes().length);
out.flush();
s = "Yes this another data$";
out.write(s.getBytes(),0,s.getBytes().length);
out.flush();
socket.shutdownInput();
socket.shutdownOutput();
socket.close();
Thread.currentThread().interrupt();

```

and
C#(for testing)

```
System.Net.Sockets.TcpClient clientSocket = new System.Net.Sockets.TcpClient();
clientSocket.Connect("192.168.0.138", 11838);
NetworkStream serverStream = clientSocket.GetStream();
byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox2.Text + "$");
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();

```

On C#(testing) side, sent one data to server, and server readed the data once and blocked to wait another data.(second data same as reading it once and blocked)I just want like this.

On Java(Real)side, sent two data to server and server reading 1st data once and read same 2nd data forever. Java side is verified sent only once.

It is full data I was received. Why? its weird.

> 
> result as:
> 
> 
> 

on C#(testing)

> 
> Client request connection.
> 
> 
> Server accept and created connection.
> 
> 
> Server try Read (and Blocked)
> 
> 
> Client send >> TextBox
> 
> 
> Server received >> TextBox
> 
> 
> Server try Read (and Blocked)
> 
> 
> 

but on Java(Real):

> 
> Client request connection.
> 
> 
> Server accept and created connection.
> 
> 
> Server try Read (and Blocked)
> 
> 
> Client send >>
>  Hello!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> 
> 
> Server received >>
>  Hello!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> 
> 
> Client send >> Yes this another data
> 
> 
> Server try Read
> 
> 
> Server received >> Yes this another data
> 
> 
> Server try Read
> 
> 
> Server received >> Yes this another data
> 
> 
> Server try Read
> 
> 
> Server received >> Yes this another data
> 
> 
> Server try Read
> 
> 
> Server received >> Yes this another data
> 
> 
> Server try Read
> 
> 
> Server received >> Yes this another data
> 
> 
> Server try Read
> 
> 
> Server received >> Yes this another data
> 
> 
> (and forever and forever)
> 
> 
> 

Server code:

```
    TcpListener serverSocket = new TcpListener(IPAddress.Any, Convert.ToInt16(Ini.IniReadValue("About", "ServerPort", "MVS_VAN.info")));
    TcpClient clientSocket = default(TcpClient);
    serverSocket.Server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
    serverSocket.Start();
    clientSocket = serverSocket.AcceptTcpClient();
    serverSocket.Stop();
    NetworkStream networkStream = clientSocket.GetStream();
    byte[] bytesFrom = new byte[128000];
    do
    {
                        Socket soc = clientSocket.Client;
                        soc.Receive(bytesFrom);
                        string dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
                        dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
                        MessageBox.Show("", dataFromClient);
                        networkStream.Flush();

                    //networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize);
                    //string dataFromClient = System.Text.Encoding.ASCII.GetString(bytesFrom);
                    //dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"));
                    //tried ^ this 3 line also.

                    } while ((true));
    clientSocket.Close();
    serverSocket.Stop();

```