changed tcpserver signature

This commit is contained in:
Mike Nolan 2022-11-27 19:59:42 -06:00
parent d162f6dc1f
commit 8020a76c41
1 changed files with 11 additions and 2 deletions

13
AST.cs
View File

@ -1054,10 +1054,15 @@ namespace langtest
Expression listenIp = expressions[0]; Expression listenIp = expressions[0];
Expression listenPort = expressions[1]; Expression listenPort = expressions[1];
VariableGetValueNode? stream_name = expressions[2] as VariableGetValueNode; VariableGetValueNode? stream_name = expressions[2] as VariableGetValueNode;
Expression exp = expressions[3]; VariableGetValueNode? ip_name = expressions[3] as VariableGetValueNode;
Expression exp = expressions[4];
if(stream_name == null) throw new Exception("You must use identifier at positional arg #3 (starting from 1)"); if(stream_name == null) throw new Exception("You must use identifier at positional arg #3 (starting from 1)");
if(ip_name == null) throw new Exception("You must use identifier at positional arg #4 (starting from 1)");
string name = stream_name.Name; string name = stream_name.Name;
//tcpserver("0.0.0.0",4202,strm,{}) string ipname = ip_name.Name;
//tcpserver("0.0.0.0",4202,strm,ip,{})
TcpListener listener = new TcpListener(new IPEndPoint(IPAddress.Parse(state.BoxToString(listenIp.Evaluate(state))),(int)listenPort.Evaluate(state))); TcpListener listener = new TcpListener(new IPEndPoint(IPAddress.Parse(state.BoxToString(listenIp.Evaluate(state))),(int)listenPort.Evaluate(state)));
listener.Start(); listener.Start();
while(true) while(true)
@ -1067,6 +1072,10 @@ namespace langtest
var s=state.NewScope(); var s=state.NewScope();
long str =s.CreateStream(stream); long str =s.CreateStream(stream);
s.SetVariable(name,str); s.SetVariable(name,str);
string? ip=clt.Client?.RemoteEndPoint?.ToString();
if(string.IsNullOrWhiteSpace(ip)) ip="";
s.SetVariable(ipname,s.CreateBox(ip));
exp.Execute(s); exp.Execute(s);
s.CloseStream(str); s.CloseStream(str);
} }