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
code from c# to x#
-
- Posts: 248
- Joined: Fri Oct 14, 2016 7:09 am
code from c# to x#
Hi Juraj,
Not sure about the precise syntax in X#, but the C# is equivalent to
StreamWriter writer = new StreamWriter(stream, Encoding.ASCII);
writer.AutoFlush = true;
HTH
Nick
Not sure about the precise syntax in X#, but the C# is equivalent to
StreamWriter writer = new StreamWriter(stream, Encoding.ASCII);
writer.AutoFlush = true;
HTH
Nick
code from c# to x#
Jurai,
the line:
IIRC, there's new syntax added to X# for setting the property already in the constructor, but this should work...
EDIT: got curious:
was my idea, but help mentions: " This will only work if there are public properties", and AutoFlush is protect...
Wonder, how C# circumnavigates that hurdle![Wink ;)](https://dt9qzg9h465rt.cloudfront.net/phpBB3/images/smilies/icon_e_wink.gif)
Karl
the line:
Code: Select all
VAR writer := StreamWriter {stream, Encoding.ASCII}
writer:AutoFlush := TRUE
EDIT: got curious:
Code: Select all
VAR writer := StreamWriter{stream, Encoding.ASCII}{AutoFlush := TRUE}
Wonder, how C# circumnavigates that hurdle
![Wink ;)](https://dt9qzg9h465rt.cloudfront.net/phpBB3/images/smilies/icon_e_wink.gif)
Karl
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
code from c# to x#
thank you for the quick reply
Juraj
Juraj
-
- Posts: 248
- Joined: Fri Oct 14, 2016 7:09 am
code from c# to x#
Hi Karl,
I think you'll find AutoFlush is a public property.
Nick
I think you'll find AutoFlush is a public property.
Nick
code from c# to x#
Nick,
hmm - in XIDE i had written "writer:", got in the pop-up list "PR Autoflush" - and read that as "protect", possibly this is "property"?
If so, i shouldn't get:
error XS9002: Parser: unexpected input 'writer'
for
LOCAL writer AS StreamWriter
writer := StreamWriter{stream, Encoding.ASCII}{AutoFlush:=TRUE} // here
or, probably, i misunderstand the concept![Wink ;)](https://dt9qzg9h465rt.cloudfront.net/phpBB3/images/smilies/icon_e_wink.gif)
Karl
PS: for this variation:
VAR writer := StreamWriter{stream, Encoding.ASCII}{AutoFlush:=TRUE}
i see:
error XS9002: Parser: unexpected input 'VAR'
@Chris, as an aside: the popup-dialog "errorpanel copied to clipboard", OK, is a PITA. Show a "Copied" and autodissappear after 1sec![Smile :)](https://dt9qzg9h465rt.cloudfront.net/phpBB3/images/smilies/icon_e_smile.gif)
hmm - in XIDE i had written "writer:", got in the pop-up list "PR Autoflush" - and read that as "protect", possibly this is "property"?
If so, i shouldn't get:
error XS9002: Parser: unexpected input 'writer'
for
LOCAL writer AS StreamWriter
writer := StreamWriter{stream, Encoding.ASCII}{AutoFlush:=TRUE} // here
or, probably, i misunderstand the concept
![Wink ;)](https://dt9qzg9h465rt.cloudfront.net/phpBB3/images/smilies/icon_e_wink.gif)
Karl
PS: for this variation:
VAR writer := StreamWriter{stream, Encoding.ASCII}{AutoFlush:=TRUE}
i see:
error XS9002: Parser: unexpected input 'VAR'
@Chris, as an aside: the popup-dialog "errorpanel copied to clipboard", OK, is a PITA. Show a "Copied" and autodissappear after 1sec
![Smile :)](https://dt9qzg9h465rt.cloudfront.net/phpBB3/images/smilies/icon_e_smile.gif)
Regards
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
Karl
(on Win8.1/64, Xide32 2.20, X#2.20.0.3)
-
- Posts: 248
- Joined: Fri Oct 14, 2016 7:09 am
code from c# to x#
I don't use XIDE so I'm not sure, but logically only (publicly) visible methods and properties will show in the Intellisense.
I imagine the compiler error is something to do with the in-line instantiation syntax - I remember there was a discussion about this between Robert and Phil a while back, but I can't pin down the thread at this moment.
Nick
I imagine the compiler error is something to do with the in-line instantiation syntax - I remember there was a discussion about this between Robert and Phil a while back, but I can't pin down the thread at this moment.
Nick
code from c# to x#
Hi Karl (& all),
In x# this feature works at the moment only when instantiating on object through a default constructor (with no arguments):
If you try to use the constructor with the int param (so call it with TestClass{123}), it will not work. Not sure why it was implemented like that, but I suspect when this feature was added in the language, it was only supported like that by the c# compiler that we were using back then, too. Since then c# got more sophisticated in this matter, but we didn't add the new syntax to remain on par. Just a guess, not absolutely sure, but will open a bug report about this and Robert or Nikos will check further.
About XIDE and the "Pr" in front of identifiers in the member completion list, yes it stands for "Property". "Fi" for Fields, "Me" for methods etc. About the dialog when copying contents from the Errors window, really this is that much annoying? Do you copy/ contents THAT often? But I just realized I still haven't added an option to copy only the current line...aargh, sorry about that, will do it now so I won't forget it again.
Chris
In x# this feature works at the moment only when instantiating on object through a default constructor (with no arguments):
Code: Select all
CLASS TestClass
EXPORT nField AS INT
PROPERTY Prop AS STRING AUTO
CONSTRUCTOR()
SUPER()
RETURN
CONSTRUCTOR(nAdditionalConstructor AS INT)
SUPER()
RETURN
END CLASS
FUNCTION Start() AS VOID
VAR o := TestClass{}{nField := 1 , Prop := "test"}
? o:nField
? o:Prop
RETURN
About XIDE and the "Pr" in front of identifiers in the member completion list, yes it stands for "Property". "Fi" for Fields, "Me" for methods etc. About the dialog when copying contents from the Errors window, really this is that much annoying? Do you copy/ contents THAT often? But I just realized I still haven't added an option to copy only the current line...aargh, sorry about that, will do it now so I won't forget it again.
Chris
Chris Pyrgas
XSharp Development Team
chris(at)xsharp.eu
XSharp Development Team
chris(at)xsharp.eu