very strange System.Net.Sockets.SocketException

What can be a possible cause

When my program running on a notebook connects the server, it gets the System.Net.Sockets.SocketException.

I try to ping the server by the domain name from the notebook. It's OK. So not related to domain name resolution or network stability problem.

I try to telnet to the server from the notebook directly and issue some commands. It's OK also. So not related to any firewall.

It just happens in a few notebooks in the same network.... what can be the possible cause

The following is the code.

if(ConnectSocketThread==null || !ConnectSocketThread.IsAlive)
{
ConnectSocketThread = new Thread( new ThreadStart(this.ConnectSocketThreadFunction) );
ConnectSocketThread.Name = "ConnectSocketThread";
ConnectSocketThread.Start();
}
ConnectSocketThread.Join(7000);

private void ConnectSocketThreadFunction()
{
while(true)
{
if(socket!=null && socket.Connected)
return;
else if(socket==null)
{
Thread.Sleep(30);
}
else
{
try
{
this.endPoint = new IPEndPoint(Dns.Resolve(Global.server).AddressList[0], Global.port);
this.socket.Connect(this.endPoint);
}
catch (Exception ex)
{
MessageBox.Show("ConnectSocketThread: (" + socket.Connected.ToString() + ")\n" + ex.ToString());
return;
}
}
}
}



Answer this question

very strange System.Net.Sockets.SocketException

  • S.Jan

    Also see what Ilyas is saying:

    See something like this:

    catch(SocketExceptopn se)

    {

           string exceptionMessage = String.Fotmat("Message: {0} Socket Error: {1) SocketErrorCode{2}" se.Message, se.SocketError, se.SocketErrorCode);

    }

    This will help in identifying exact cause of the problem!

    Best Regards,



  • Sean K. Campbell

    Thanks!!! I will try and see if I can come back with anything.

    RizwanSharp wrote:

    Also see what Ilyas is saying:

    See something like this:

    catch(SocketExceptopn se)

    {

    string exceptionMessage = String.Fotmat("Message: {0} Socket Error: {1) SocketErrorCode{2}" se.Message, se.SocketError, se.SocketErrorCode);

    }

    This will help in identifying exact cause of the problem!

    Best Regards,


  • rajbasav

    can you give us the specific socketexception error message

  • skynes

    Why Not

    See this:

    http://msdn2.microsoft.com/en-us/library/system.net.dns_methods.aspx

    Check both functions and see effect of both!

    Best Regards,



  • Smealum

    OK

    RizwanSharp wrote:

    You should atlease give it a try. They have depricated it from the newer version of .Net. May be there are some problems like this on new Wifi Tech etc.

    We dont have to spend anything more than changing 2-3 lines of code. Let's See what happens.

    Best Regards,


  • Highflier64

    I cannot find Dns.GetHostEntry()

    I now use Dns.GetHostByName(server).AddressList[0];

    is that OK

    RizwanSharp wrote:

    Dns.Resolve() is depricated in .Net 2.0 so if you are using it in .Net 2.0 try to change it to Dns.GetHostEntry() etc and see what happens.

    Best Regards,


  • matiaswoloski

    Cyrus Chan wrote:

    Please Mark the Helpfull Post(s) as answered .

    Best Regards,



  • asmith48

    I changed the code as follows and that computer in the Wireless LAN can connect to the server. Thanks everybody!

    try
    {
    if(this.ipAddress==null)
    {
    this.ipAddress = Dns.GetHostByName(Global.server).AddressList[0];
    }
    this.endPoint = new IPEndPoint(this.ipAddress, Global.port);
    this.socket.Connect(this.endPoint);
    }
    catch (SocketException se)
    {
    string errorMesg = String.Format("Message: {0}\nNativeErrorCode: {1)\nErrorCode: {2}", se.Message, se.NativeErrorCode, se.ErrorCode);
    MessageBox.Show("ConnectSocketThread1: " + errorMesg);
    MessageBox.Show("ConnectSocketThread2: " + se.ToString());
    return;
    }
    catch (Exception ex)
    {
    MessageBox.Show("ConnectSocketThread3: " + ex.ToString());
    return;
    }

    RizwanSharp wrote:

    Dns.Resolve() is depricated in .Net 2.0 so if you are using it in .Net 2.0 try to change it to Dns.GetHostEntry() etc and see what happens.

    Best Regards,


  • Duncan_

    Dns.Resolve() is depricated in .Net 2.0 so if you are using it in .Net 2.0 try to change it to Dns.GetHostEntry() etc and see what happens.

    Best Regards,



  • BobH

    I dont have the error message now but I remember it's kinda the text/explanation you see in the Object browser in VS2003 for System.Net.Sockets.SocketException.

     

     ahmedilyas wrote:
    can you give us the specific socketexception error message


  • Citrus

    You should atlease give it a try. They have depricated it from the newer version of .Net. May be there are some problems like this on new Wifi Tech etc.

    We dont have to spend anything more than changing 2-3 lines of code. Let's See what happens.

    Best Regards,



  • LouArnold

    Thanks. But I think it should not be the cause. I'm using .Net 2.0 on my PC and doesnt have any problem with the code.

    The network where the notebook having problem with the code connected is a Wireless LAN. I wonder if anything can go wrong with that Wireless LAN. Any experience to share

     

     RizwanSharp wrote:

    Dns.Resolve() is depricated in .Net 2.0 so if you are using it in .Net 2.0 try to change it to Dns.GetHostEntry() etc and see what happens.

    Best Regards,


  • WinFXGuy

    please do post back the error message you get :-) (Message or InnerException)

  • very strange System.Net.Sockets.SocketException