Help me to convert this code in Java into a C# code
-
Help me to convert this code in Java into a C# code
import java.io.*;
import java.net.*;public class simpleServer
{
public static void main(String args[])
{
// Message terminator
char EOF = (char)0x00;try { // create a serverSocket connection on port 9999 ServerSocket s = new ServerSocket(2055); System.out.println("Server started. Waiting for connections..."); // wait for incoming connections Socket incoming = s.accept(); BufferedReader data\_in = new BufferedReader( new InputStreamReader(incoming.getInputStream())); PrintWriter data\_out = new PrintWriter(incoming.getOutputStream()); data\_out.println("Welcome! type EXIT to quit." + EOF); data\_out.flush(); boolean quit = false; // Waits for the EXIT command while (!quit) { String msg = data\_in.readLine(); if (msg == null) quit = true; if (!msg.trim().equals("EXIT")) { data\_out.println("You sayed: <b>" + msg.trim() + "</b>" + EOF); data\_out.flush(); } else { quit = true; } } } catch (Exception e) { System.out.println("Connection lost"); } }
}
-
Help me to convert this code in Java into a C# code
import java.io.*;
import java.net.*;public class simpleServer
{
public static void main(String args[])
{
// Message terminator
char EOF = (char)0x00;try { // create a serverSocket connection on port 9999 ServerSocket s = new ServerSocket(2055); System.out.println("Server started. Waiting for connections..."); // wait for incoming connections Socket incoming = s.accept(); BufferedReader data\_in = new BufferedReader( new InputStreamReader(incoming.getInputStream())); PrintWriter data\_out = new PrintWriter(incoming.getOutputStream()); data\_out.println("Welcome! type EXIT to quit." + EOF); data\_out.flush(); boolean quit = false; // Waits for the EXIT command while (!quit) { String msg = data\_in.readLine(); if (msg == null) quit = true; if (!msg.trim().equals("EXIT")) { data\_out.println("You sayed: <b>" + msg.trim() + "</b>" + EOF); data\_out.flush(); } else { quit = true; } } } catch (Exception e) { System.out.println("Connection lost"); } }
}
You forgot to say "pretty please?". I'm going to sulk, now. :(
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
Help me to convert this code in Java into a C# code
import java.io.*;
import java.net.*;public class simpleServer
{
public static void main(String args[])
{
// Message terminator
char EOF = (char)0x00;try { // create a serverSocket connection on port 9999 ServerSocket s = new ServerSocket(2055); System.out.println("Server started. Waiting for connections..."); // wait for incoming connections Socket incoming = s.accept(); BufferedReader data\_in = new BufferedReader( new InputStreamReader(incoming.getInputStream())); PrintWriter data\_out = new PrintWriter(incoming.getOutputStream()); data\_out.println("Welcome! type EXIT to quit." + EOF); data\_out.flush(); boolean quit = false; // Waits for the EXIT command while (!quit) { String msg = data\_in.readLine(); if (msg == null) quit = true; if (!msg.trim().equals("EXIT")) { data\_out.println("You sayed: <b>" + msg.trim() + "</b>" + EOF); data\_out.flush(); } else { quit = true; } } } catch (Exception e) { System.out.println("Connection lost"); } }
}
help me please :)
-
help me please :)
Sure. Show me what you've done yourself, and point out which bits aren't functioning as you expect, and I'll help you fix them. I'm not however going to do all the work for you.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus) -
Help me to convert this code in Java into a C# code
import java.io.*;
import java.net.*;public class simpleServer
{
public static void main(String args[])
{
// Message terminator
char EOF = (char)0x00;try { // create a serverSocket connection on port 9999 ServerSocket s = new ServerSocket(2055); System.out.println("Server started. Waiting for connections..."); // wait for incoming connections Socket incoming = s.accept(); BufferedReader data\_in = new BufferedReader( new InputStreamReader(incoming.getInputStream())); PrintWriter data\_out = new PrintWriter(incoming.getOutputStream()); data\_out.println("Welcome! type EXIT to quit." + EOF); data\_out.flush(); boolean quit = false; // Waits for the EXIT command while (!quit) { String msg = data\_in.readLine(); if (msg == null) quit = true; if (!msg.trim().equals("EXIT")) { data\_out.println("You sayed: <b>" + msg.trim() + "</b>" + EOF); data\_out.flush(); } else { quit = true; } } } catch (Exception e) { System.out.println("Connection lost"); } }
}
Why do you need to convert it? Just make it a method and use it, C#.NET allows you to mix languages.
-
Sure. Show me what you've done yourself, and point out which bits aren't functioning as you expect, and I'll help you fix them. I'm not however going to do all the work for you.
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)I have tried in this mode:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Configuration;class Server
{
public static void Main()
{
// Message terminator
char EOF = (char)0x00;try
{
IPAddress ipAd = IPAddress.Parse("127.0.0.1");/* Initializes the Listener */
TcpListener myList = new TcpListener(ipAd, 2055);/* Start Listeneting at the specified port */
myList.Start();Console.WriteLine("The server is running. Waiting for a connection....");
Socket soc = myList.AcceptSocket();
Stream s = new NetworkStream(soc);
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);sw.WriteLine("Benvenuti sul server! digita EXIT per disconnetterti." + EOF);
sw.Flush();bool quit = false;
while (!quit)
{
string msg = sr.ReadLine();if (msg == null) quit = true;
if (msg != "EXIT")
{
sw.WriteLine("Guest: <b>" + msg + "</b>" + EOF);
sw.Flush();
}
else
{
quit = true;
}} // end while
}
catch (Exception e)
{
Console.WriteLine(e.Message);}
}
} -
I have tried in this mode:
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Configuration;class Server
{
public static void Main()
{
// Message terminator
char EOF = (char)0x00;try
{
IPAddress ipAd = IPAddress.Parse("127.0.0.1");/* Initializes the Listener */
TcpListener myList = new TcpListener(ipAd, 2055);/* Start Listeneting at the specified port */
myList.Start();Console.WriteLine("The server is running. Waiting for a connection....");
Socket soc = myList.AcceptSocket();
Stream s = new NetworkStream(soc);
StreamReader sr = new StreamReader(s);
StreamWriter sw = new StreamWriter(s);sw.WriteLine("Benvenuti sul server! digita EXIT per disconnetterti." + EOF);
sw.Flush();bool quit = false;
while (!quit)
{
string msg = sr.ReadLine();if (msg == null) quit = true;
if (msg != "EXIT")
{
sw.WriteLine("Guest: <b>" + msg + "</b>" + EOF);
sw.Flush();
}
else
{
quit = true;
}} // end while
}
catch (Exception e)
{
Console.WriteLine(e.Message);}
}
}That compiles with no errors or warnings. So, what's the problem?
Dave
BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
Why are you using VB6? Do you hate yourself? (Christian Graus)