Socket Programming - Converting from Java to C#

Jan 30 2005 12:13 PM
Hello, I am currently trying to convert an application, originally written in Java, to C#. The application deals primarily with socket programming, something with which I have very little experience. I tried using the Java Language Conversion Assistant, but it wasn't much help, as the classes I am attempting to convert don't have any direct .NET analogs. I am including a code snippet, in the hopes that someone might be able to give me some general guidelines. Once I get some idea of which .NET classes to use to replace the original Java ones, I should be able to proceed on my own. Snippet (in original Java) import java.net.*; import java.io.*; import java.util.logging.*; import java.net.*; import java.io.*; import java.util.logging.*; public abstract class UDPServer extends Thread { private int bufferSize; // in bytes protected DatagramSocket ds; Logger logger = Logger.getLogger("com.core.dashboard"); public UDPServer(int port, int bufferSize) throws SocketException { this.bufferSize = bufferSize; this.ds = new DatagramSocket(port); } public UDPServer(int port) throws SocketException { this(port, 8192); //logger.info("Setting up UDP server for port: " + port); } public void run() { //logger.info("UDPServer.java: in thread for UDP server: "); byte[] buffer = new byte[bufferSize]; while (true) { DatagramPacket incoming = new DatagramPacket(buffer, buffer.length); try { //logger.info("UDPServer: waitting for packet"); ds.receive(incoming); //logger.info("UDPServer: Got UDP data packet: " + incoming); this.respond(incoming); } catch (IOException e) { System.err.println(e); } } // end while } // end run public abstract void respond(DatagramPacket request); } I know, of course, that I can't inherit from the Thread class in .NET (I'm using delegates). My main concern is finding the NET equivalent for the DatagramPacket and Datagram Socket classes. Any help or advice would be very much appreciated!!! Thanks in advance....

Answers (2)