473,787 Members | 2,971 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem about socket.poll

I have writen the following souce code :

m_Socket = new Socket(AddressF amily.InterNetw ork,
SocketType.Stre am, ProtocolType.Tc p);
m_Socket.Blocki ng = false;

try
{
m_Socket.Connec t(ipEndPoint);
}
catch (SocketExceptio n e)
{
int timePace = 500000;

try
{
bool retCode = m_Socket.Poll(t imePace,
SelectMode.Sele ctWrite); //Step1 , check the server status.
m_Context.IsLas tPollSuccess = retCode;

//System.Console. WriteLine( retCode );
if (retCode == true)
{
m_Context.LastS ocketErrorCode = 0;
m_Context.IsSoc ketConnected = true;
}
else
{
throw new
MyAppException( MyAppExceptionR es.GetString(My AppExceptionRes .MyAppException _16_SystemCallE rror,
new object[] { "Socket.Pol l", e.ErrorCode
}));

//Step2 poll method return false, throw an
general error message.
}
// set socket option
//......
}
catch (SocketExceptio n e1)
{ //Step3 according the errorcode to get the error
message.
if (e1.ErrorCode == 10049 || e1.ErrorCode == 10051 )
// WSAEADDRNOTAVAI L=10049 , WSAENETUNREACH= 10051
{
throw new
MyAppException( MyAppExceptionR es.GetString(My AppExceptionRes .MyAppException _17_HostAddress ErrorInHostFile ));
}
else if (e1.ErrorCode == 10060) // WSAETIMEDOUT
=10060
{
throw new
MyAppException( MyAppExceptionR es.GetString(My AppExceptionRes .MyAppException _14_CannotCommu nicateWithServe r));
}
else if (e1.ErrorCode == 10048) // WSAEADDRINUSE
=10048
{
throw new
MyAppException( MyAppExceptionR es.GetString(My AppExceptionRes .MyAppException _18_ServerHasBe enUsedAddress)) ;
}
else if (e1.ErrorCode == 10061) //
WSAECONNREFUSED =10061
{
throw new
MyAppException( MyAppExceptionR es.GetString(My AppExceptionRes .MyAppException _19_ServerRefus edConnection));
}
else if (e1.ErrorCode == 10050) // WSAENETDOWN
=10050
{
throw new
MyAppException( MyAppExceptionR es.GetString(My AppExceptionRes .MyAppException _12_GeneralNetw orkError));
}
else if (e1.ErrorCode == 10055) // WSAENOBUFS =10055
{
throw new
MyAppException( MyAppExceptionR es.GetString(My AppExceptionRes .MyAppException _13_Insufficien tMemory));
}
else
{
throw new
MyAppException( MyAppExceptionR es.GetString(My AppExceptionRes .MyAppException _16_SystemCallE rror,
new object[] { "Socket.Pol l", 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 2044

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

Similar topics

0
2107
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 to use 2.1.1 to avoid any crossover issues/problems. Thanks ;-) So ... Using gcc Im compiling Python2.1.1, and it configures quite reasonably, the ./configure is trascribed at the bottom of this email. now once I have done that I compile it...
1
2562
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 WSAEWOULDBLOCK, then I do a poll with timeout to see if I can connect to the remote host. When the poll returns true, the socket Connected property is still false. Why is this? sock.Blocking = false; try { sock.connect (...)
3
4638
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 and then fires a datareceived event. Within the waitingloop there is a timeout function, but I want the the 'last-time-socket-used' variable set when the socket is finished sending. When I send by System.Net.Sockets.Socket.Send(buffer()) (<--this...
0
1425
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 thread. In each thread I have a loop like below: the data_available method is a wrapper around Socket.Poll() so I can use it in miliseconds instead of micro. Basicly I read a command via a streamreader and that all works, then depending on...
0
4523
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 work but I have some problems with outside.Receive, it gives me a SocketException "An existing connection was forcibly closed by the remote host" at random times, also outside.Poll will say it has data but outside.Receive returns with nothing...
0
1674
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 WSAEWOULDBLOCK, then I do a poll with timeout to see if I can connect to the remote host. When the poll returns true, the socket Connected property is still false. Why is this? sock.Blocking = false; try { sock.connect (...)
2
702
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 more data to expect). Sometimes, Socket.Available returns 0 but the other end of the connection did not close it ! 2) This class will be used by many other classes so I have to use the
5
7107
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 connection of an open Asyncore socket. Calling the socket.close() nor the socket.shutdown(2) calls seem to work. The only way I can close the connection without creating the error below is to have the client close the connection. I have the...
21
5671
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 Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
0
10363
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10169
jinu1996
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9964
tracyyun
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8993
agi2029
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5398
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2894
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.