code from c# to x#
Posted: Thu Dec 14, 2017 12:52 pm
Hi All,
I need send mesage from pc to another pc. I found an example on net in C#, but I would like to use it in x# in core dialect. How to translate How to translate a designated line?
Or is there a better solution?
Sample:
//************************************************************
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Text;
namespace TcpEchoServer
{
public class TcpEchoServer
{
public static void Main()
{
Console.WriteLine("Starting echo server...");
int port = 1234;
TcpListener listener = new TcpListener(IPAddress.Loopback, port);
listener.Start();
TcpClient client = listener.AcceptTcpClient();
NetworkStream stream = client.GetStream();
// ************* This row ********************************************************************
StreamWriter writer = new StreamWriter(stream, Encoding.ASCII) { AutoFlush = true }
// *******************************************************************************************
StreamReader reader = new StreamReader(stream, Encoding.ASCII);
while (true)
{
string inputLine = "";
while (inputLine != null)
{
inputLine = reader.ReadLine();
writer.WriteLine("Echoing string: " + inputLine);
Console.WriteLine("Echoing string: " + inputLine);
}
Console.WriteLine("Server saw disconnect from client.");
}
}
}
}
//**********************************************************************************
Thanks for advice
Juraj
I need send mesage from pc to another pc. I found an example on net in C#, but I would like to use it in x# in core dialect. How to translate How to translate a designated line?
Or is there a better solution?
Sample:
//************************************************************
using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Text;
namespace TcpEchoServer
{
public class TcpEchoServer
{
public static void Main()
{
Console.WriteLine("Starting echo server...");
int port = 1234;
TcpListener listener = new TcpListener(IPAddress.Loopback, port);
listener.Start();
TcpClient client = listener.AcceptTcpClient();
NetworkStream stream = client.GetStream();
// ************* This row ********************************************************************
StreamWriter writer = new StreamWriter(stream, Encoding.ASCII) { AutoFlush = true }
// *******************************************************************************************
StreamReader reader = new StreamReader(stream, Encoding.ASCII);
while (true)
{
string inputLine = "";
while (inputLine != null)
{
inputLine = reader.ReadLine();
writer.WriteLine("Echoing string: " + inputLine);
Console.WriteLine("Echoing string: " + inputLine);
}
Console.WriteLine("Server saw disconnect from client.");
}
}
}
}
//**********************************************************************************
Thanks for advice
Juraj