I'm using .NET 2.0 VS 2005
I'm creating a function that dos something similar to the.
SmoApplication.EnumAvailableSqlServers() function. But for som resone
I get an error or do i?. The problem is that the program just return
from the function when it reach the recive part( reviced =
socket.Receive(bytBuffer); ), below here you can se the code. I used
eathereal to check the package that is send and reviced, that looks
all fine. I do revice the correct package from the SQLServer. Dos
anyone have a clue here? im lost after 3 days hard work on it.
Thanks is advanced
Rene
// RECIVED STRING FROM SQL SERVER
ServerName;MASTER;InstanceName;BKUPEXEC;IsClustere d;No;Version;8.00.194;tcp;2369;npMASTER\pipe\M$BKU PEXEC\sql\query;;ServerName;MASTER;InstanceName;SQ LEXPRE;Islustered;No;Version;9.00.2047.00;;
ArrayList servers = new ArrayList();
ArrayList list = null;
SqlServerInfo info = new SqlServerInfo();
Socket socket = new Socket(AddressFamily.InterNetwork,
SocketType.Dgram, ProtocolType.Udp);
socket.EnableBroadcast = true;
socket.ReceiveTimeout = 3000;
try
{
// ask for all MSSQL servers
byte[] msg = new byte[] { 0x02 };
byte[] bytBuffer = new byte[1024];
int reviced = 0;
IPEndPoint endP = new IPEndPoint(IPAddress.Broadcast, 1434);
socket.SendTo(msg, endP);
do
{
// IT JUST STOPS HERE AND RETURN FROM THE FUNCTION WITH AN
// EMPTY LIST SOMETIMES IT THROWS AN EXCEPTION
// broadcast A connection attempt failed because the connected
// party did not properly respond after a period of time, or
// established connection failed because connected host has
// failed to respond socket recive
reviced = socket.Receive(bytBuffer);
// There can be more than one instance on the same server
list = info.ParseServers(bytBuffer);
for (int i = 0; i < list.Count; i++)
{
servers.Add(new SqlServerInfo(null, (string)list[i]));
}
socket.SetSocketOption(SocketOptionLevel.Socket,
SocketOptionName.ReceiveTimeout, 300);
} while (reviced != 0);
}
catch (SocketException socex)
{
const int WSAETIMEDOUT = 10060;// Connection timed out.
const int WSAEHOSTUNREACH = 10065; // No route to host.
// Re-throw if it's not a timeout.
if (socex.ErrorCode == WSAETIMEDOUT || socex.ErrorCode ==
WSAEHOSTUNREACH)
{
// Just go away
}
else
{
throw;
}
}
finally
{
socket.Close();
}
// Copy from the untyped but expandable ArrayList, to a
// type-safe but fixed array of SqlServerInfos.
SqlServerInfo[] aServers = new SqlServerInfo[servers.Count];
servers.CopyTo(aServers);
return aServers; 2 5677
Why are you setting receive timeout to 300ms? Also, remember you don't
receive messages, you receive bytes. So any receive could return 1 or more
bytes until receive returns 0 (i.e. shutdown). So your
ParseServers(bytBuffer) method may fail at times.
--
William Stacey [MVP]
"Rene Sørensen" <re**@deltadk.dkwrote in message
news:3o********************************@4ax.com...
| I'm using .NET 2.0 VS 2005
|
| I'm creating a function that dos something similar to the.
| SmoApplication.EnumAvailableSqlServers() function. But for som resone
| I get an error or do i?. The problem is that the program just return
| from the function when it reach the recive part( reviced =
| socket.Receive(bytBuffer); ), below here you can se the code. I used
| eathereal to check the package that is send and reviced, that looks
| all fine. I do revice the correct package from the SQLServer. Dos
| anyone have a clue here? im lost after 3 days hard work on it.
|
| Thanks is advanced
|
| Rene
|
|
| // RECIVED STRING FROM SQL SERVER
|
ServerName;MASTER;InstanceName;BKUPEXEC;IsClustere d;No;Version;8.00.194;tcp;2369;npMASTER\pipe\M$BKU PEXEC\sql\query;;ServerName;MASTER;InstanceName;SQ LEXPRE;Islustered;No;Version;9.00.2047.00;;
|
| ArrayList servers = new ArrayList();
| ArrayList list = null;
| SqlServerInfo info = new SqlServerInfo();
| Socket socket = new Socket(AddressFamily.InterNetwork,
| SocketType.Dgram, ProtocolType.Udp);
|
| socket.EnableBroadcast = true;
| socket.ReceiveTimeout = 3000;
|
|
| try
| {
| // ask for all MSSQL servers
| byte[] msg = new byte[] { 0x02 };
| byte[] bytBuffer = new byte[1024];
| int reviced = 0;
| IPEndPoint endP = new IPEndPoint(IPAddress.Broadcast, 1434);
| socket.SendTo(msg, endP);
| do
| {
| // IT JUST STOPS HERE AND RETURN FROM THE FUNCTION WITH AN
| // EMPTY LIST SOMETIMES IT THROWS AN EXCEPTION
| // broadcast A connection attempt failed because the connected
| // party did not properly respond after a period of time, or
| // established connection failed because connected host has
| // failed to respond socket recive
|
| reviced = socket.Receive(bytBuffer);
|
| // There can be more than one instance on the same server
| list = info.ParseServers(bytBuffer);
| for (int i = 0; i < list.Count; i++)
| {
| servers.Add(new SqlServerInfo(null, (string)list[i]));
| }
| socket.SetSocketOption(SocketOptionLevel.Socket,
| SocketOptionName.ReceiveTimeout, 300);
| } while (reviced != 0);
| }
| catch (SocketException socex)
| {
| const int WSAETIMEDOUT = 10060;// Connection timed out.
| const int WSAEHOSTUNREACH = 10065; // No route to host.
|
| // Re-throw if it's not a timeout.
| if (socex.ErrorCode == WSAETIMEDOUT || socex.ErrorCode ==
| WSAEHOSTUNREACH)
| {
| // Just go away
| }
| else
| {
| throw;
| }
| }
| finally
| {
| socket.Close();
| }
| // Copy from the untyped but expandable ArrayList, to a
| // type-safe but fixed array of SqlServerInfos.
| SqlServerInfo[] aServers = new SqlServerInfo[servers.Count];
| servers.CopyTo(aServers);
| return aServers;
|
Thanks for your reply
>Why are you setting receive timeout to 300ms?
Well so fare it never reach the point where it's set so the problem
has to be found elseware.
>Also, remember you don't receive messages, you receive bytes. So any receive could return 1 or more bytes until receive returns 0 (i.e. shutdown). So your ParseServers(bytBuffer) method may fail at times.
Yes your are rigth about that, but problem is it never reach the
"ParseServers(bytBuffer)" it just stops at the
"socket.Recive(byteBuffer)" and i mean realy stops.
It never gets to this point "list = info.ParseServers(bytBuffer);" or
futher, only when a exception ocure. It's like
"socket.Recive(byteBuffer)" acts like an return for the fucntion, for
me thats prety wierd?
On Thu, 28 Sep 2006 21:37:31 -0400, "William Stacey [MVP]"
<wi************@gmail.comwrote:
>Why are you setting receive timeout to 300ms? Also, remember you don't receive messages, you receive bytes. So any receive could return 1 or more bytes until receive returns 0 (i.e. shutdown). So your ParseServers(bytBuffer) method may fail at times.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bryan Olson |
last post by:
Here's the problem: Suppose we use:
import socket
f = some_socket.makefile()
Then:
f.read() is efficient, but verbose, and incorrect (or at
least does not play will with others);
|
by: Ivar |
last post by:
Hi,
Is SocketOptionName.ReciveTimeout usable with asyncronous socket methods ?
With Recive method it works but BeginRecive can't get it working.
|
by: faktujaa |
last post by:
Hi,
I am having some problem with callback used in socket implementation.
private static void Connect(string strPrtrIPAddr, int intPrtrPort, ref
Socket rsocClient)
{
try
{
// Create remote end...
|
by: Adam Clauss |
last post by:
There seems to be various methods to determine when the remote client disconnects, but all of them I have seen are Synchronous.
AKA: Right before you try to send or receive data, check.
Is there...
|
by: gilad |
last post by:
I am trying to write a program that will send an HTTP request and get an
HTTP response. However, I am having trouble getting the full payload
(i.e. the web page) returned from the host. I am using...
| |
by: Jarod_24 |
last post by:
Background:
Im working on a remote console (rcon) for accessing dedicated quake3 servers.
Quake 3 uses UDP and Out Of Bands packets to communicate in ASCII text
(see more here...
|
by: Macca |
last post by:
Hi,
My application uses an asynchronous socket server. The question I have is
what i should set my socket server buffer size to.
I will know the size of each data packet sent across the...
|
by: atlaste |
last post by:
Hi,
In an attempt to create a full-blown webcrawler I've found myself
writing a wrapper around the Socket class in an attempt to make it
completely async, supporting timeouts and some scheduling...
|
by: phantom3008 |
last post by:
Hi i want to record an audio file and send it using UDP . I have server/client program and i'm able to send text file and recive that into another file .But how do i send audio file ..can anyone help...
|
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,...
|
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,...
| |
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...
|
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...
|
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: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |