user9135075
user9135075

Reputation:

C# - A request to send data was disallowed because the socket is not connected

I am coding a chat application as an intro for me to sockets. I was trying to get the clients and servers IP address and save it to a richtextbox. I put it into a thread and whenever there is a connection pending, it will accept and get the IP address, but it fails out in debug mode. Please advice. Thank you so much!

enter image description here

Upvotes: 1

Views: 337

Answers (1)

Doug Johnson
Doug Johnson

Reputation: 560

AcceptTcpClient() returns the TcpClient for the incoming connection. Try this code:

var client = tcpListener.AcceptTcpClient();
var remoteEndPoint = _currentClient.Client.RemoteEndPoint;

Upvotes: 1

Related Questions