java.net.ServerSocket under J# & .NET Framework

Hi,

I've converted our Java application to C# recently, This is an Client/Server application exchanging data over tcpip sockets. Conversion was successful. But I've noticed that java.net.ServerSocket.close() does not interrupt accept() method as a result Application does not shutdown.

Can you please tell me where I'm going wrong ;-)

Thanks,

Sameer


Answer this question

java.net.ServerSocket under J# & .NET Framework

  • pablog

    Can you put the example please...

    I need try this example, thanks!




  • PedroMarques

    Just to understand your scenario well,

    1. Which version of .NET Framework and J# Redist is being used by you (VS 2003 or Visual Studio 2005 Beta 1/2)

    2. Is the converted code using J# class libraries(java.net.ServerSocket) from C# code.

    3. It would be great if you could post a code snippet illustrating the issue.

    Thanks,

  • veeruu

    Hi,

    I recently received reply for my post on my e-mail from Jaiprakash, for some reason it was pointing to an non-existent post (id = 53480) let me add it to this message.

    Hi Sameer,
    Try calling Socket.ShutDown() before calling Socket.Close(). It should do the needful.

    For connection-oriented protocols, it is recommended that you call ShutDown before calling the Close method. This ensures that all data is sent and received on the connected socket before it is closed.

    Please reply if it doesn't help.

    Thanks,
    Jaiprakash


    Thanks to Jaiprakash for answering th question but he may have mis-understood the problem, I've no issue with using System.Net.Sockets.Socket, problem is using java.net.ServerSocket from vjslib.dll. which does not have Shutdown() method. In Java(under JVM) you simply call ServerSocket.close() and it'll stop waiting for incoming connections, where as under .net same(J#) code will continue to wait. even Thread.CurrentThread.Interrupt/Suspend/Abort is not useful to stop it.

    I'll be grateful if someone can help.

    Thanks,

    Sameer


  • Scott Anderson

    Hi Varun,

    Thanks for your reply,
    We are using VS 2005 Beta 2 and these are J# Libraries used from C#. Originally this was a Client/Server application communicating over TCP/IP sockets. We first converted the client to C# & J# and left the server side in Java and now we are trying to convert the server side to J#.
    J# code is basically connection management and protocol parsing.

    here is an code snippet

    Thanks,
    Sameer

    namespace ConsoleApplication1

    {

       class Program

       {

          static java.net.ServerSocket server;

          static void Main(string[] args)

          {

             System.Threading.Thread thr = new System.Threading.Thread(new       
             System.Threading.
    ThreadStart(AcceptConnection));

             thr.Start();

             object obj = new object();

             lock (obj)

             {

                System.Threading.Monitor.Wait(obj, 3000);

             }

             System.Console.WriteLine("Closing Server socket");

             server.close();

             thr.Join();

       }

       private static void AcceptConnection()

       {

          server = new java.net.ServerSocket(60000);

          System.Console.WriteLine("Listening on port 60000");

          server.accept();

          System.Console.WriteLine("Server socket closed");

       }

    }

    }


  • wackoyacky

    Hi Sameer,

    Jaiprakash had mistaken ServerSocket for System.Net.Sockets.Socket, However he had deleted the post as he realised the misunderstanding.

    We are looking into your code and will get back to you soon.

    Thanks,

  • DearDearDear

    Hi Sameer,

    You were doing the right thing here. This problem wont repro for you in final release of Visual studio 2005.

    Thanks,


  • java.net.ServerSocket under J# & .NET Framework