Server remains hang when sending
<p>I'm writting a client(Android) - server(c#) application. I get the code from here:
<a href="http://stackoverflow.com/questions/6387579/how-to-make-client-on-android-listen-to-server-on-c">How to make client on Android listen to server on C#?</a>
Everythings is working fine, when i just send message from the client to server, and from server to client (closing the socket on server side). Now, what i want is : send message to server, receive message from server, then send again a message to server. The server hangs at sending the message. If i close the socket on server side after sending, it gives a dispose error, and i can's send the data from the server.</p>

<p>My server code is:</p>

<pre><code>/*************************************SERVER*****************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.Net.Sockets;

namespace SERVER2
{
    class Program
    {
        public static void Main()
        {
            try
            {
                IPAddress ipAd = IPAddress.Parse("192.168.2.102");

                TcpListener myList = new TcpListener(ipAd, 18001);

                myList.Start();

                Console.WriteLine("The server is running at port 18001...");
                Console.WriteLine("The local End point is  :" +
                                  myList.LocalEndpoint);
                Console.WriteLine("Waiting for a connection.....");
                 m:
                Socket s = myList.AcceptSocket();
                Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);

                byte[] b = new byte[100];
                int k = s.Receive(b);

                char cc = ' ';
                string test = null;
                Console.WriteLine("Recieved1...");
                for (int i = 0; i &lt; k - 1; i++)
                {
                    cc = Convert.ToChar(b[i]);
                    test += cc.ToString();
                }
                Console.WriteLine("Received characters1: "+test);

                ASCIIEncoding asen = new ASCIIEncoding();
                s.Send(asen.GetBytes("The string was recieved by the server."));
                Console.WriteLine("\nSent Acknowledgement");
                //s.Close(); &lt;-if i enable this, i get a dispose error

                k = s.Receive(b);//i get dispose error here

                cc = ' ';
                test = null;
                Console.WriteLine("Recieved2...");
                for (int i = 0; i &lt; k - 1; i++)
                {
                    cc = Convert.ToChar(b[i]);
                    test += cc.ToString();
                }
                Console.WriteLine("Received characters2: " + test);

                /* clean up */
                goto m;
                s.Close();
                myList.Stop();

            }
            catch (Exception e)
            {
                Console.WriteLine("Error..... " + e.Message);
            }
            Console.ReadLine();
        }

    }
}
</code></pre>

<p>My client code is:</p>

<pre><code>/******************************CLIENT*****************************************/
    Socket socket = null;
        try 
        {
            Toast.makeText(context,"IP: "+ip+" port: "+port,10000).show();
            InetAddress serverAddr = InetAddress.getByName(ip); 
            socket = new Socket(serverAddr, port);
        } 
        catch (UnknownHostException e1) 
        {
            Toast.makeText(context,"UnknownHostException ",10000).show();
        } 
        catch (IOException e1) 
        {
            Toast.makeText(context,"IOException ",10000).show();
        }

        String message = "1";

        PrintWriter out = null;
        BufferedReader in = null;

        try { 
            Log.d("TCP", "C: Sending: '" + message + "'"); 

            /*write*/
            out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true);
            out.println(message);
            out.flush();
            /*read*/
            in = new BufferedReader(new InputStreamReader(socket.getInputStream())); 
            String text = "";
            String finalText = "";
            while ((text = in.readLine()) != null) 
            {
                finalText += text;
                }
            Toast.makeText(context, "FinalText: "+finalText, 10000).show();
            Log.d("TCP", "C: Sent.");
            Log.d("TCP", "C: Done."); 
            in.close();        

            /*write*/
            out = new PrintWriter( new BufferedWriter( new OutputStreamWriter(socket.getOutputStream())),true);
            out.println(message);
            out.flush();
        } catch(Exception e) { 
            Log.e("TCP", "S: Error", e); 
        } finally { 
            try {
                socket.close();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } 
        } 
</code></pre>

<p>Thanks advanced !!!</p>
