Hi, when I try to query for MaxConnections with GetSockOpt I am seeing an
exception and cannot figure out what is going on. Here is a quick and dirty
test program and the output, hopefully you can
point me in the right direction:
---- Code -----
{
Socket s = new Socket (AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.IP);
IPEndPoint ip = new IPEndPoint (IPAddress.Any, 9876);
try
{
outputText.AppendText ("Attempt1:");
outputText.AppendText (Environment.NewLine);
s.GetSocketOption (SocketOptionLevel.Socket,
SocketOptionName.MaxConnections);
}
catch (SocketException se1)
{
outputText.AppendText (se1.ToString ());
}
try
{
outputText.AppendText (Environment.NewLine);
outputText.AppendText (Environment.NewLine);
outputText.AppendText ("Attempt2:");
outputText.AppendText (Environment.NewLine);
s.GetSocketOption (SocketOptionLevel.IP,
SocketOptionName.MaxConnections);
}
catch (SocketException se2)
{
outputText.AppendText (se2.ToString ());
}
try
{
outputText.AppendText (Environment.NewLine);
outputText.AppendText (Environment.NewLine);
outputText.AppendText ("Attempt3:");
outputText.AppendText (Environment.NewLine);
s.GetSocketOption (SocketOptionLevel.Tcp,
SocketOptionName.MaxConnections);
}
catch (SocketException se3)
{
outputText.AppendText (se3.ToString ());
}
----- Ouput -----
Attempt1:
System.Net.Sockets.SocketException: An unknown, invalid, or unsupported
option or level was specified in a getsockopt or setsockopt call
at System.Net.Sockets.Socket.GetSocketOption(SocketOptionLevel
optionLevel, SocketOptionName optionName)
at simplesocket.Form1.button1_Click(Object sender, EventArgs e) in
d:\teststuff\simplesocket\simplesocket\form1.cs:line 112
Attempt2:
System.Net.Sockets.SocketException: An unknown, invalid, or unsupported
option or level was specified in a getsockopt or setsockopt call
at System.Net.Sockets.Socket.GetSocketOption(SocketOptionLevel
optionLevel, SocketOptionName optionName)
at simplesocket.Form1.button1_Click(Object sender, EventArgs e) in
d:\teststuff\simplesocket\simplesocket\form1.cs:line 124
Attempt3:
System.Net.Sockets.SocketException: An invalid argument was supplied
at System.Net.Sockets.Socket.GetSocketOption(SocketOptionLevel
optionLevel, SocketOptionName optionName)
at simplesocket.Form1.button1_Click(Object sender, EventArgs e) in
d:\teststuff\simplesocket\simplesocket\form1.cs:line 136
Jared Parsons [MSFT] - 24 Jan 2005 19:38 GMT
I've never played with that SocketOption before but I think that you need to
bind the socket to the IPEndPoint before you can query that SocketOption

Signature
Jared Parson [MSFT]
jaredpar@online.microsoft.com
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
> Hi, when I try to query for MaxConnections with GetSockOpt I am seeing an
> exception and cannot figure out what is going on. Here is a quick and
[quoted text clipped - 68 lines]
> at simplesocket.Form1.button1_Click(Object sender, EventArgs e) in
> d:\teststuff\simplesocket\simplesocket\form1.cs:line 136