473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

List open Sockets in .NET

6
Is there a way to determine if a particular socket is open on the localhost?

I'm looking for something that will either return a list of open sockets or a function that will take a port number and return some sort of status value, boolean or otherwise.

I am trying to write an app that will determine if another application I wrote has started correctly and is listening for incoming requests.

Thanks
Feb 27 '07 #1
5 2061
vijaydiwakar
579 512MB
Is there a way to determine if a particular socket is open on the localhost?

I'm looking for something that will either return a list of open sockets or a function that will take a port number and return some sort of status value, boolean or otherwise.

I am trying to write an app that will determine if another application I wrote has started correctly and is listening for incoming requests.

Thanks
u may try this
Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub GetSerialPortNames()
  3.     ' Show all available COM ports.
  4.     For Each sp As String In My.Computer.Ports.SerialPortNames
  5.         ListBox1.Items.Add(sp)
  6.     Next
  7. End Sub
  8.  
  9.  
  10.  
Feb 28 '07 #2
jman
6
u may try this
Expand|Select|Wrap|Line Numbers
  1.  
  2. Sub GetSerialPortNames()
  3.     ' Show all available COM ports.
  4.     For Each sp As String In My.Computer.Ports.SerialPortNames
  5.         ListBox1.Items.Add(sp)
  6.     Next
  7. End Sub
  8.  
  9.  
  10.  
Thanks for the response, but I should have been more specific:
1. I am talking about a tcp socket port, not a serial port.
2. I would prefer a C#-ish way of doing this.
Feb 28 '07 #3
radcaesar
759 Expert 512MB
//Creates the Socket for sending data over TCP.
Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
ProtocolType.Tcp );

// Connects to host using IPEndPoint.
s.Connect(EPhost);
if (!s.Connected)
{
strRetPage = "Unable to connect to host";
}
// Use the SelectWrite enumeration to obtain Socket status.
if(s.Poll(-1, SelectMode.SelectWrite)){
Console.WriteLine("This Socket is writable.");
}
else if (s.Poll(-1, SelectMode.SelectRead)){
Console.WriteLine("This should not print. Because this is not a listening Socket," +
" no incoming connecton requests are expected. " );
}
else if (s.Poll(-1, SelectMode.SelectError)){
Console.WriteLine("This Socket has an error.");
}
Feb 28 '07 #4
jman
6
Thanks radcaesar.

I had tried a similiar approach using TcpClient but that caused the program listening to the socket to wait for an incoming message. This solution does not.

Thanks
Feb 28 '07 #5
jman
6
Thanks radcaesar.

I had tried a similiar approach using TcpClient but that caused the program listening to the socket to wait for an incoming message. This solution does not.

Thanks

It seems I was mistaken. This still causes the listening program to expect data to be sent. The problem is that under certain circumstances the program will freeze waiting for the data to be transmitted.
Feb 28 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Dennis Hueckelheim | last post by:
Hallo everybody, I have a problem with a little socket script. ----- snipp ----- $out_clients = socket_accept($socket_out); $http_welcome = "HTTP/1.0 200 OK\r\nContent-type:...
2
by: Tero Saarni | last post by:
Hi, I have several threads communicating with each other using events stored in Queues. Threads block on Queue.get() until somebody publishes an event in thread's event queue. I need to add...
6
by: Claire | last post by:
When i close a client connection by using System.Net.Sockets.TcpClient.Close() method it remains open and viewable with netstat -an. public void Disconnect() { if (myClient == null) return;...
4
by: BadOmen | last post by:
Hi, What is the different between 'System.Net.Sockets.Socket' and 'System.Net.Sockets.TcpClient'? When do I use System.Net.Sockets.TcpClient and System.Net.Sockets.Socket?? Yours, Jonas
3
by: Michael Maercker | last post by:
hi! i'm really not into networking at all and have now been asigned the task of porting a vb6-code into vb.net (compact framework, in this case) and the code uses the winsock-control. i quickly...
0
by: nezoat | last post by:
Here is some working code to open the specified TCP port on the gateway nat device or firewall, and forward it to the calling machine. Great for p2p apps. The newsgroups are such a great...
4
by: techiepundit | last post by:
I'm a Python newbie who just started learning the language a few weeks ago. So these are beginner questions. I have a list of sockets that I use for select.select calls like this: ...
7
by: Lee | last post by:
Hey all, I'm using the following code to send stuff accross the network, appologies for it being in full, but I've really no idea exactly where this error is occuring. =======network...
1
by: truezplaya | last post by:
Hey Once again i'm stuck. I have an arrayList of members and i wish to cycle through this list and send a message to all connected members of that list.Here is what i thought would work. Please...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.