Click here to Skip to main content
15,792,870 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone,

i am trying to listen port number 3389 using Tcplistner class as follow.

 static void Main(string[] args)
            // port number 3389 reserved as RDP listener port.
            // 3389 port for listening rdp connection request.
            TcpListener tcpListener = new TcpListener(3389);
            tcpListener.Start(); // here i got exception
            Socket socketForClient = tcpListener.AcceptSocket();

at tcpListener.Start();
i got exception saying

"Only one usage of each socket address (protocol/network address/port) is normally permitted"

how to come out of this?

Thanks all.
Updated 8-Feb-12 7:58am
Richard MacCutchan 8-Feb-12 12:59pm    
That suggests that there is already another application or system service listening on that port.
Bhavin Jagad 8-Feb-12 13:21pm    
ya, its right. since, 3389 port is reserved for RDP connection there might be windows service which is listening that port for incoming RDP connection. i just want to know the ip of the pc which made request for RDP connection;
Richard MacCutchan 9-Feb-12 3:39am    
You need to use a packet sniffer, plenty of free ones around.

1 solution

As the comment in your code says:
// port number 3389 reserved as RDP listener port.
this is standard RDP port, and if you have RDP enabled on your computer the RDP service is using this port.

The solution is to disable/stop RDP service or change the default listening port.

If you only want to monitor for new connections you could use GetActiveTcpConnections method:
using System.Net.NetworkInformation;
var RdpConnections = IPGlobalProperties.GetIPGlobalProperties().GetActiveTcpConnections().Where(c => c.LocalEndPoint.Port == 3389);

Call this periodically to get new connections.
Loop through RdpConnections and look at their RemoteEndPoint for address.
Share this answer
Bhavin Jagad 8-Feb-12 13:26pm    
Thanks for your reply.
my purpose is to only know the ip of the computer which made RDP connection request to my computer. i dont want to block RDP connection. i don't want to use system log info.
sjelen 9-Feb-12 9:19am    
In that case you don't need TcpListener, look at updated solution.
I didn't try it but it should work.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900