[Mono-list] System.Net.Sockets.SocketException

Timothy Parez tpsoftware@users.sourceforge.net
20 Mar 2003 09:43:51 +0100


Hi,
you were correct,
it does work perfectly on Linux.

I'll try to post a bug report, but I have very little time.

Thnx.
Timothy.


Op do 20-03-2003, om 01:32 schreef Simon Waite:
> Plaintexted for the reply
> 
> Hi Tim,
> 
> ----
> But I get the following with the mono runtime:
> 
> Unhandled Exception:
> TPSoftware.Q3PlugsNet.Exceptions.ConnectionRefusedException
> : The connection was refused by the remote host: 195.130.132.155:27961
> Some sort of w32 error occurred ---> System.Net.Sockets.SocketException:
> Some so
> rt of w32 error occurred
> in (unmanaged) 06 System.Net.Sockets.Socket:RecvFrom_internal
> (intptr,byte[],int
> ,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&)
> ----
> 
> Looks like some odd interaction between mono and win32s Winsock2 layer.
> 
> Have you tried to run your app on a linux as well ? I would be pleased
> to give it a try under linux for you.
> 
> Otherwise see if you can make a simple testcase, and file a bugzilla report!
> 
> Regards,
> 
> Simon
> 
> 
> 
> 
> ----- Original Message -----
> From: Timothy Parez
> To: mono-list@ximian.com
> Sent: Wednesday, March 19, 2003 11:19 PM
> Subject: Re: [Mono-list] System.Net.Sockets.SocketException
> 
> 
> Update 2:
> The error doesn't seem to be gone at all :(
> So the problem remains.
> ----- Original Message -----
> From: Timothy Parez
> To: mono-list@ximian.com
> Sent: Wednesday, March 19, 2003 11:52 PM
> Subject: Re: [Mono-list] System.Net.Sockets.SocketException
> 
> 
> Update:
> 
> It seems that when I changed everything to ASCII instead of UTF7 everything
> works fine and there are no more socket exceptions. Although I don't get the
> link between the encoding and the socket exceptions, so it may be
> coïncidence.
> 
> Can someone verify this ?
> ----- Original Message -----
> From: Timothy Parez
> To: mono-list@ximian.com
> Sent: Wednesday, March 19, 2003 11:08 PM
> Subject: [Mono-list] System.Net.Sockets.SocketException
> 
> 
> Hi,
> 
> I'm writing a set of class libs for .NET/Mono,
> except for the UTF7 Encoding in my other post, it should work fine.
> And it does on .NET, but not on Mono.
> 
> I don't know where to start, but I'll try to explain.
> 
> First of all I have a Base Class which amongst other members has the
> following function
> 
>  private void ExecuteQuery()
>   {
>    UdpClient client = new UdpClient();
>    //Connect to the server and send the query data
>    try
>    {
>     client.Connect(ip,port);
>     client.Send(data,data.Length);
>    }
>    catch
>    {
>     client.Close();
>     throw new Exceptions.InvalidHostException("Unknown host: " + ip);
>    }
> 
>    //Listen for a response - This is the client side
>    IPEndPoint serverIPEndPoint = new IPEndPoint(IPAddress.Any,0);
> 
>    //Receive the response
>    try
>    {
>     queryResponse = client.Receive(ref serverIPEndPoint);
>    }
>    catch (Exception e)
>    {
>     throw new Exceptions.ConnectionRefusedException("The connection was
> refused by the remote host: " + ip + ":" + port.ToString() + "\n" +
> e.Message,e);
>    }
>    finally
>    {
>     client.Close();
>    }
>   }
> 
> As you can see it sends a n array of bytes to the server and receives some
> in return.
> 
> Then I have a derived class which has 2 important functions:
> 
>   public string RequestStatus()
>   {
>    //Create the byte[] array to send
>    byte[] query =
> {0xFF,0xFF,0xFF,0xFF,0x67,0x65,0x74,0x73,0x74,0x61,0x74,0x75,0x73,0xA};
> 
>    //Create a new separator
>    char separator = Convert.ToChar(10);
> 
>    //A statusRequest consists of both rules and players separated by
> char(10)
>    string[] response = this.QueryToString(query).Split(separator);
> 
>    //Get the rules and players
>    string rules = this.RulesToXml(response[0]);
>    string players = this.PlayersToXml(response);
> 
>    return
> this.CreateXmlBody("Quake3","statusRequest",string.Concat(rules,players));
>   }
> 
> And
> 
>   public string RequestInfo()
>   {
>    //Create the byte[] array to send
>    byte[] query =
> {0xFF,0xFF,0xFF,0xFF,0x67,0x65,0x74,0x69,0x6E,0x66,0x6F,0xA};
> 
>    //Query the server and get the response in a string
>    string response = this.QueryToString(query);
> 
>    //Create the default xml body and put the rules in it
>    string returnValue =
> this.CreateXmlBody("Quake3","infoRequest",this.RulesToXml(response));
> 
>    //return the XML
>    return returnValue;
>   }
> 
> As you can see there is almost no difference between them.
> Now they both run fine with the .NET runtime, but with the mono runtime the
> .RequestStatus() fails.
> 
> When does it fail well when the QueryToString function is called,
> so if I run RequestInfo() the QueryToString function is called and it all
> works fine,
> if I run RequestStatus() the QueryToString function is called and it goes
> wrong.
> In my opinion the only difference so far is the array of bytes to be sent.
> 
> Example:
> 
> Let's say I use the following code for an application
> 
> using System;
> using TPSoftware.Q3PlugsNet;
> using TPSoftware.Q3PlugsNet.Exceptions;
> 
> class MainClass
> {
>  public static void Main(string[] args)
>  {
> 
>   //Create a new Q3Query
> 
>  // Q3Query quakeClient = new Q3Query("195.130.132.153",27961);
>   Q3Query quakeClient = new Q3Query("195.130.132.155",27961);
> 
>   try
>   {
>    string info = quakeClient.RequestStatus();
>    Console.WriteLine(info);
>   }
>   catch (Exception e)
>   {
>    Console.WriteLine("ERROR:");
>    Console.WriteLine("\n" + e.ToString());
> 
>   }
>   finally
>   {
>   Console.ReadLine();
>   }
>  }
> }
> 
> Well then I get the following result with .NET runtime
> 
> <?xml version="1.0" encoding="utf-7" standalone="yes"?><Q3Plugs.NET><Query
> type=
> "statusRequest" protocol="Quake3"><Server ipadress="195.130.132.155"
> port="27961
> " /><Rules count="28"><rule name="capturelimit"><![CDATA[8]]></rule><rule
> name="
> sv_floodProtect"><![CDATA[0]]></rule><rule
> name="sv_maxPing"><![CDATA[0]]></rule
> ><rule name="sv_minPing"><![CDATA[0]]></rule><rule
> name="sv_maxRate"><![CDATA[15
> 000]]></rule><rule name="sv_punkbuster"><![CDATA[0]]></rule><rule
> name="sv_maxcl
> ients"><![CDATA[14]]></rule><rule name="sv_hostname"><![CDATA[Telenet Q3A
> OSP CA
>  Server]]></rule><rule name="timelimit"><![CDATA[0]]></rule><rule
> name="fraglimi
> t"><![CDATA[25]]></rule><rule name="dmflags"><![CDATA[8]]></rule><rule
> name="ver
> sion"><![CDATA[Q3 1.32 linux-i386 Oct  7 2002]]></rule><rule
> name="g_gametype"><
> ![CDATA[5]]></rule><rule name="protocol"><![CDATA[68]]></rule><rule
> name="mapnam
> e"><![CDATA[q3dm6]]></rule><rule
> name="sv_privateClients"><![CDATA[2]]></rule><r
> ule name="sv_allowDownload"><![CDATA[1]]></rule><rule
> name="server_promode"><![C
> DATA[0]]></rule><rule name="server_cq3"><![CDATA[0]]></rule><rule
> name="g_needpa
> ss"><![CDATA[0]]></rule><rule
> name="server_ospauth"><![CDATA[2]]></rule><rule na
> me="gamename"><![CDATA[osp]]></rule><rule name="gameversion"><![CDATA[OSP
> v1.03]
> ]></rule><rule name="Players_Red"><![CDATA[2 4 6 8 10 ]]></rule><rule
> name="Play
> ers_Blue"><![CDATA[1 3 5 7 9 ]]></rule><rule
> name="Score_Red"><![CDATA[15]]></ru
> le><rule name="Score_Blue"><![CDATA[17]]></rule><rule
> name="Score_Time"><![CDATA
> [Round 33/49]]></rule></Rules><Players count="10"><Player score="20"
> ping="15"><
> ![CDATA["^5DA^4.^5Ch^7a^5o^7s"]]></Player><Player score="12"
> ping="24"><![CDATA[
> "UnnamedPlaye^1r"]]></Player><Player score="48"
> ping="38"><![CDATA["^b^0*^n^7mnl
> ^b^0*"]]></Player><Player score="38"
> ping="38"><![CDATA["^xffffff^9eHk^b^4*^n^0T
> ^9N^0T"]]></Player><Player score="80"
> ping="25"><![CDATA["^5B^7osje^5R"]]></Play
> er><Player score="85"
> ping="24"><![CDATA["^x00FF00^2911^xFFFFFF^0>>^7SaTo"]]></P
> layer><Player score="18" ping="52"><![CDATA["^4jerome"]]></Player><Player
> score=
> "96" ping="41"><![CDATA["^x3366FF^7e^0C^7'.E^0mo^7Z"]]></Player><Player
> score="1
> 1" ping="16"><![CDATA["crypto"]]></Player><Player score="73"
> ping="40"><![CDATA[
> "^0fearl^33^0ss"]]></Player></Players></Query></Q3Plugs.NET>
> 
> But I get the following with the mono runtime:
> 
> Unhandled Exception:
> TPSoftware.Q3PlugsNet.Exceptions.ConnectionRefusedException
> : The connection was refused by the remote host: 195.130.132.155:27961
> Some sort of w32 error occurred ---> System.Net.Sockets.SocketException:
> Some so
> rt of w32 error occurred
> in (unmanaged) 06 System.Net.Sockets.Socket:RecvFrom_internal
> (intptr,byte[],int
> ,int,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&)
> in <0x00004> 06 System.Net.Sockets.Socket:RecvFrom_internal
> (intptr,byte[],int,i
> nt,System.Net.Sockets.SocketFlags,System.Net.SocketAddress&)
> in <0x00155> 00 System.Net.Sockets.Socket:ReceiveFrom
> (byte[],int,int,System.Net
> .Sockets.SocketFlags,System.Net.EndPoint&)
> in <0x00180> 00 System.Net.Sockets.Socket:ReceiveFrom
> (byte[],int,int,System.Net
> .Sockets.SocketFlags,System.Net.EndPoint&)
> in <0x0002a> 00 System.Net.Sockets.Socket:ReceiveFrom
> (byte[],System.Net.EndPoin
> t&)
> in <0x000af> 00 System.Net.Sockets.UdpClient:Receive
> (System.Net.IPEndPoint&)
> in <0x0016b> 00 TPSoftware.Q3PlugsNet.QueryBase:ExecuteQuery ()
> --- End of inner exception stack trace ---
> 
> in <0x002b4> 00 TPSoftware.Q3PlugsNet.QueryBase:ExecuteQuery ()
> in <0x0005b> 01 System.MulticastDelegate:invoke_void ()
> 
> 
> However if I change the above code to:
> 
> using System;
> using TPSoftware.Q3PlugsNet;
> using TPSoftware.Q3PlugsNet.Exceptions;
> 
> class MainClass
> {
>  public static void Main(string[] args)
>  {
> 
>   //Create a new Q3Query
> 
>  // Q3Query quakeClient = new Q3Query("195.130.132.153",27961);
>   Q3Query quakeClient = new Q3Query("195.130.132.155",27961);
> 
>   try
>   {
>    string info = quakeClient.RequestInfo(); // RequestInfo instead of
> RequestStatus !!!!!!!!
>    Console.WriteLine(info);
>   }
>   catch (Exception e)
>   {
>    Console.WriteLine("ERROR:");
>    Console.WriteLine("\n" + e.ToString());
> 
> 
>   }
>   finally
>   {
>   Console.ReadLine();
>   }
>  }
> }
> 
> I get the following output with .NET
> 
> <?xml version="1.0" encoding="utf-7" standalone="yes"?><Q3Plugs.NET><Query
> type=
> "infoRequest" protocol="Quake3"><Server ipadress="195.130.132.155"
> port="27961"
> /><Rules count="9"><rule name="game"><![CDATA[osp]]></rule><rule
> name="punkbuste
> r"><![CDATA[0]]></rule><rule name="pure"><![CDATA[1]]></rule><rule
> name="gametyp
> e"><![CDATA[5]]></rule><rule name="sv_maxclients"><![CDATA[12]]></rule><rule
> nam
> e="clients"><![CDATA[2]]></rule><rule
> name="mapname"><![CDATA[q3dm6]]></rule><ru
> le name="hostname"><![CDATA[Telenet Q3A OSP CA Server]]></rule><rule
> name="proto
> col"><![CDATA[68]]></rule></Rules></Query></Q3Plugs.NET>
> 
> And the following output with mono (don't mind the encoding, that's another
> bug)
> 
> ???xml version???1.0?? encoding???utf-7?? standalone???yes????
> ??Q3Plugs.NET? ??
> Query type???infoRequest?? protocol???Quake3??? ??Server
> ipadress???195.130.132.
> 155?? port???27961?? /? ???Rules count????+BDJAAARO?????
> name?????+BDJAAARO???+E
> JwMQFQE+AFs-osp???+-???/rule???+QAA-rule
> name???????+BDJAAARO???+EJwMQFQE+AFs-0?
> ??+-???/rule???+QAA-rule
> name?????+BDJAAARO???+EJwMQFQE+AFs-1???+-???/rule???+QA
> A-rule name??????+BDJAAARO???+EJwMQFQE+AFs-5???+-???/rule???+QAA-rule
> name????+B
> G8AAA-maxclients???+AAAETEEl???+-AFs-12???+-???/rule???+QAA-rule
> name??????+BDJA
> AARO???+EJwMQFQE+AFs-2???+-???/rule???+QAA-rule
> name??????+BDJAAARO???+EJwMQFQE+
> AFs-q3dm6???+-???/rule???+QAA-rule
> name??????+BDJAAARO???+EJwMQFQE+AFs-Telenet Q
> 3A OSP CA Server???+-???/rule???+QAA-rule
> name??????+BDJAAARO???+EJwMQFQE+AFs-68
> ???+-???/rule???+QAA-/Rules?????/Query? ??/Q3Plugs.NET?
> 
> So this works fine (more or less) and doesn't throw any errors.
> 
> So my question: Why does RequestStatus cause an error while RequestInfo does
> not.
> 
> If you want to view the full sources of the library please visit:
> http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/q3plugs/Q3Plugs.NET/
> 
> Thnx,
> Timothy P.
> 
> 
> 
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.463 / Virus Database: 262 - Release Date: 17/03/2003
> 
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.463 / Virus Database: 262 - Release Date: 18/03/2003
> 
> _______________________________________________
> Mono-list maillist  -  Mono-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-list