473,320 Members | 1,914 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Problem about socket.poll

I have writen the following souce code :

m_Socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
m_Socket.Blocking = false;

try
{
m_Socket.Connect(ipEndPoint);
}
catch (SocketException e)
{
int timePace = 500000;

try
{
bool retCode = m_Socket.Poll(timePace,
SelectMode.SelectWrite); //Step1 , check the server status.
m_Context.IsLastPollSuccess = retCode;

//System.Console.WriteLine( retCode );
if (retCode == true)
{
m_Context.LastSocketErrorCode = 0;
m_Context.IsSocketConnected = true;
}
else
{
throw new
MyAppException(MyAppExceptionRes.GetString(MyAppEx ceptionRes.MyAppException_16_SystemCallError,
new object[] { "Socket.Poll", e.ErrorCode
}));

//Step2 poll method return false, throw an
general error message.
}
// set socket option
//......
}
catch (SocketException e1)
{ //Step3 according the errorcode to get the error
message.
if (e1.ErrorCode == 10049 || e1.ErrorCode == 10051 )
// WSAEADDRNOTAVAIL=10049 , WSAENETUNREACH=10051
{
throw new
MyAppException(MyAppExceptionRes.GetString(MyAppEx ceptionRes.MyAppException_17_HostAddressErrorInHos tFile));
}
else if (e1.ErrorCode == 10060) // WSAETIMEDOUT
=10060
{
throw new
MyAppException(MyAppExceptionRes.GetString(MyAppEx ceptionRes.MyAppException_14_CannotCommunicateWith Server));
}
else if (e1.ErrorCode == 10048) // WSAEADDRINUSE
=10048
{
throw new
MyAppException(MyAppExceptionRes.GetString(MyAppEx ceptionRes.MyAppException_18_ServerHasBeenUsedAddr ess));
}
else if (e1.ErrorCode == 10061) //
WSAECONNREFUSED=10061
{
throw new
MyAppException(MyAppExceptionRes.GetString(MyAppEx ceptionRes.MyAppException_19_ServerRefusedConnecti on));
}
else if (e1.ErrorCode == 10050) // WSAENETDOWN
=10050
{
throw new
MyAppException(MyAppExceptionRes.GetString(MyAppEx ceptionRes.MyAppException_12_GeneralNetworkError)) ;
}
else if (e1.ErrorCode == 10055) // WSAENOBUFS =10055
{
throw new
MyAppException(MyAppExceptionRes.GetString(MyAppEx ceptionRes.MyAppException_13_InsufficientMemory));
}
else
{
throw new
MyAppException(MyAppExceptionRes.GetString(MyAppEx ceptionRes.MyAppException_16_SystemCallError,
new object[] { "Socket.Poll", e1.ErrorCode
}));

}

}

accor ding to the "user-fixable errors", the url is :
http://www.sockets.com/a_c2.htm#UserFixableErrors

I am try to use the socket.poll method to check the server status after
the socket.connect method, and it will throw out exception with a
specified errormessage according to the server status.

but, the program has never arrived at the step 3.

The poll method always return false without exception , even if I input
one error IP and Port, i draw out the network.

I do not know what's wrong with my source code, are there some bugs in
my code?

In addition, who can tell me when the poll method will throw exception?
would you please to tell me how to create such a condition to invoke
the exception?

anyway, thanks to all of you .

Jan 10 '07 #1
0 2004

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dave Harrison | last post by:
Ok before I start, please dont mail me telling me to use a more recent version of Python, I _would_ use 2.2.x but due to an existing framework all based on using 2.1.1 I have been specifically told...
1
by: ETYC | last post by:
I am not sure if this is a bug or not but it seems strange to me. If I set the tcp socket blocking to false and do a connect, then I can catch the socketexception. If the exception is...
3
by: Robert A. van Ginkel | last post by:
Hello Fellow Developer, I use the System.Net.Sockets to send/receive data (no tcpclient/tcplistener), I made a receivethread in my wrapper, the receivethread loops/sleeps while waiting for data...
0
by: Tony Caduto | last post by:
Hi, I am developing a socket server in C# and I want it to be blocking. Anyway I have it working with threads, as each client connects the socket spawned from the accept method is sent to a client...
0
by: soaphead | last post by:
Can I use Socket.Poll for blocking socket? It is unclear in documentation if I can use this with a synchronous socket, can my code possibly turn a synchronous socket to asynchronous? It seems to...
0
by: et-yc | last post by:
I am not sure if this is a bug or not but it seems strange to me. If I set the tcp socket blocking to false and do a connect, then I can catch the socketexception. If the exception is...
2
by: Droopy | last post by:
Hi, I try to implement a reusable socket class to send and receive data. It seems to work but I have 2 problems : 1) I rely on Socket.Available to detect that the connection is closed (no...
5
by: JamesHoward | last post by:
I have a problem with python's asyncore module throwing a bad file descriptor error. The code might be difficult to copy here, but the problem is essentially: The server wants to sever the...
21
by: puzzlecracker | last post by:
Problem: I send a lot of requests to the application (running on a different box, of course), and I receive back responses from the app . Below: socket corresponds to Socket socket=new...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.