For computer name: Dns.GetHostEntry(stringIP).HostName should work. For the ip, I've used this before:
string sIP = (mySocket.RemoteEndPoint.ToString().Split(':'))[0];
IPAddress tempIP = IPAddress.Parse(sIP);
This will seperate the port number from the IP in the RemoteEndPoint, then will parse this as an IP address. Though there might be a better way to do this...
UPDATE again:
hello skatamatic, i try out the code you gave, but still didnt show the client' pc name :( don't know what did i wrong, but thankfully it show the client's ip address, thanks :)
for the ip address code, have error when the client disconnected. string sIP = (workerSocket.RemoteEndPoint.ToString().Split(':'))[0];
it said NullReferenceException was unhandled by user code "Object reference not set to an instance of an object."
how to fix it? what should i change?
here is the code i modified again:
void UpdateClientList()
{
listView1.Items.Clear();
for(int i = 0; i < m_workerSocketList.Count; i++)
{
string clientKey = Convert.ToString(i+1);
Socket workerSocket = (Socket)m_workerSocketList[i];
ListViewItem result = new ListViewItem();
string clientinfo = Dns.GetHostName();
IPHostEntry he = Dns.GetHostEntry(clientinfo);
string sIP = (workerSocket.RemoteEndPoint.ToString().Split(':'))[0];
IPAddress tempIP = IPAddress.Parse(sIP);
if(workerSocket != null)
{
if(workerSocket.Connected)
{
result.SubItems.Add(he.HostName);
result.SubItems.Add(tempIP.ToString());
listView1.Items.Add(clientKey);
listView1.Items.Add(result);
}
}
}
}
thanks again.