Open ZengerU opened 6 years ago
Best way to understand is break right after your datareceived function then look at e in debugger. Here's an example:
LantronixServer.DelimiterDataReceived += ReceivedLineTCP; //Create DataReceived handler
Sub ReceivedLineTCP(sender As object, e As Message);
try
{
//You have to convert RemoteEndPoint to IPEndpoint
//Then do whatever with IPEndpoint
var ip = ((Net.IPEndPoint)e.TcpClient.Client.RemoteEndPoint).Address.ToString();
}
catch (Exception ex)
{
logger.Error(ex.Message.ToString());
}
}
Clients don't have a "receiving port" by default, they'll just open a random free port to send the message and close it when the message is send, so there's no reliable return port.
You'd be better of having the server return a port to the client and the client starting its own listen server, and announcing its own port and ip to the server once it starts listening for incoming messages...
Excuse me for the naive(?) question, i have little to no experience in c#. In the DataRecieved function, is there a way for the server to get the ip and the port of the sender object? Or any other way?
Thanks in advance!