Winsock2 connect taking long time to timeout

Hi,

I have a situation whereby when I call to the Winsock2's connect()
function, it takes a long time to respond back. This causes my
CPictureEx animated GIF to show hanging on the screen.

I'm thinking of creating a thread for the connect() function call so
that it will not hang my animated GIF.

Can anyone show me how to go about doing that?

TIA.

Rgds,

Mike

0
9/7/2006 9:34:48 AM
vc.mfc 33608 articles. 0 followers. Follow

7 Replies
1285 Views

Similar Articles

[PageSpeed] 27

Hi mike ,

Hope the following code snippet will help you .Please do read more abt 
CreateThraed API in MSDN where u can get good
samples of thread implementations.

InitialzeThraed() // User Defined Method
{
        DWORD dwThreadID = 0;
        CreateThraed( NULL,0,SocketConnectThread,NULL, 0,&dwThreadID) // 
WindowsAPI
}


DWORD WINAPI SocketConnectThread(LPVOID param) // Thread Fucntion
{
    while(1)
    {
        if (  Sokect.Connect  == suceess)
        {
            break;
        }
    }
    return 0;
}


Regds
Jibesh.V.P



"cybernerdsx2" <fongjengkum@gmail.com> wrote in message 
news:1157621688.117308.128760@m79g2000cwm.googlegroups.com...
> Hi,
>
> I have a situation whereby when I call to the Winsock2's connect()
> function, it takes a long time to respond back. This causes my
> CPictureEx animated GIF to show hanging on the screen.
>
> I'm thinking of creating a thread for the connect() function call so
> that it will not hang my animated GIF.
>
> Can anyone show me how to go about doing that?
>
> TIA.
>
> Rgds,
>
> Mike
> 


0
9/7/2006 2:27:44 PM
You are probably using CSocket, or synchronous sockets.  Don't do that.  The behavior you
are seeing is expected.  Note that there are some network timeouts on the order of 70
seconds, so it is assumed that you will have arbitrarily long hangs.  

Use CAsyncSocket to do your work, then it won't hang.  Try to avoid raw WinSock calls
unless you enjoy being miserable.
					joe

On 7 Sep 2006 02:34:48 -0700, "cybernerdsx2" <fongjengkum@gmail.com> wrote:

>Hi,
>
>I have a situation whereby when I call to the Winsock2's connect()
>function, it takes a long time to respond back. This causes my
>CPictureEx animated GIF to show hanging on the screen.
>
>I'm thinking of creating a thread for the connect() function call so
>that it will not hang my animated GIF.
>
>Can anyone show me how to go about doing that?
>
>TIA.
>
>Rgds,
>
>Mike
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
9/7/2006 3:24:39 PM
Hi,

Okay, I switched to using CAsyncSocket now. But having the problem of
keeping the animated GIF to animate while waiting for some IP address
to timeout.

Even if I try putting Sleep() after the call I still get the animated
GIF to hang.

Do you know how I can do it?




Joseph M. Newcomer wrote:
> You are probably using CSocket, or synchronous sockets.  Don't do that.  The behavior you
> are seeing is expected.  Note that there are some network timeouts on the order of 70
> seconds, so it is assumed that you will have arbitrarily long hangs.
>
> Use CAsyncSocket to do your work, then it won't hang.  Try to avoid raw WinSock calls
> unless you enjoy being miserable.
> 					joe
>
> On 7 Sep 2006 02:34:48 -0700, "cybernerdsx2" <fongjengkum@gmail.com> wrote:
>
> >Hi,
> >
> >I have a situation whereby when I call to the Winsock2's connect()
> >function, it takes a long time to respond back. This causes my
> >CPictureEx animated GIF to show hanging on the screen.
> >
> >I'm thinking of creating a thread for the connect() function call so
> >that it will not hang my animated GIF.
> >
> >Can anyone show me how to go about doing that?
> >
> >TIA.
> >
> >Rgds,
> >
> >Mike
> Joseph M. Newcomer [MVP]
> email: newcomer@flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm

0
9/8/2006 8:14:56 AM
cybernerdsx2 wrote:
> Hi,
> 
> Okay, I switched to using CAsyncSocket now. But having the problem of
> keeping the animated GIF to animate while waiting for some IP address
> to timeout.
> 
> Even if I try putting Sleep() after the call I still get the animated
> GIF to hang.
> 
> Do you know how I can do it?

Do you return to MFC immediately after calling Connect?  If you are in 
some kind of wait loop (or calling Sleep) then of course your animation 
will not continue.  You should be returning to MFC and, later, receive a 
call to your override of OnConnect to get the Connect final result.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
9/8/2006 1:30:19 PM
why dont you try porting your socket connection code in a thread.

Hav a try , and take rest :)

- Jibesh

"cybernerdsx2" <fongjengkum@gmail.com> wrote in message 
news:1157703296.922842.178820@i3g2000cwc.googlegroups.com...
> Hi,
>
> Okay, I switched to using CAsyncSocket now. But having the problem of
> keeping the animated GIF to animate while waiting for some IP address
> to timeout.
>
> Even if I try putting Sleep() after the call I still get the animated
> GIF to hang.
>
> Do you know how I can do it?
>
>
>
>
> Joseph M. Newcomer wrote:
>> You are probably using CSocket, or synchronous sockets.  Don't do that. 
>> The behavior you
>> are seeing is expected.  Note that there are some network timeouts on the 
>> order of 70
>> seconds, so it is assumed that you will have arbitrarily long hangs.
>>
>> Use CAsyncSocket to do your work, then it won't hang.  Try to avoid raw 
>> WinSock calls
>> unless you enjoy being miserable.
>> joe
>>
>> On 7 Sep 2006 02:34:48 -0700, "cybernerdsx2" <fongjengkum@gmail.com> 
>> wrote:
>>
>> >Hi,
>> >
>> >I have a situation whereby when I call to the Winsock2's connect()
>> >function, it takes a long time to respond back. This causes my
>> >CPictureEx animated GIF to show hanging on the screen.
>> >
>> >I'm thinking of creating a thread for the connect() function call so
>> >that it will not hang my animated GIF.
>> >
>> >Can anyone show me how to go about doing that?
>> >
>> >TIA.
>> >
>> >Rgds,
>> >
>> >Mike
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
> 


0
9/8/2006 2:54:12 PM
If you are using CAsyncSocket, there is no issue, because the GUI thread doesn't block. So
there is no "wait", and animation can continue unhindered.  That's one of they key reasons
for using CAsyncSocket.

Putting a Sleep() in is *guaranteed* to make your animation fail!  
					joe

On 8 Sep 2006 01:14:56 -0700, "cybernerdsx2" <fongjengkum@gmail.com> wrote:

>Hi,
>
>Okay, I switched to using CAsyncSocket now. But having the problem of
>keeping the animated GIF to animate while waiting for some IP address
>to timeout.
>
>Even if I try putting Sleep() after the call I still get the animated
>GIF to hang.
>
>Do you know how I can do it?
>
>
>
>
>Joseph M. Newcomer wrote:
>> You are probably using CSocket, or synchronous sockets.  Don't do that.  The behavior you
>> are seeing is expected.  Note that there are some network timeouts on the order of 70
>> seconds, so it is assumed that you will have arbitrarily long hangs.
>>
>> Use CAsyncSocket to do your work, then it won't hang.  Try to avoid raw WinSock calls
>> unless you enjoy being miserable.
>> 					joe
>>
>> On 7 Sep 2006 02:34:48 -0700, "cybernerdsx2" <fongjengkum@gmail.com> wrote:
>>
>> >Hi,
>> >
>> >I have a situation whereby when I call to the Winsock2's connect()
>> >function, it takes a long time to respond back. This causes my
>> >CPictureEx animated GIF to show hanging on the screen.
>> >
>> >I'm thinking of creating a thread for the connect() function call so
>> >that it will not hang my animated GIF.
>> >
>> >Can anyone show me how to go about doing that?
>> >
>> >TIA.
>> >
>> >Rgds,
>> >
>> >Mike
>> Joseph M. Newcomer [MVP]
>> email: newcomer@flounder.com
>> Web: http://www.flounder.com
>> MVP Tips: http://www.flounder.com/mvp_tips.htm
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
9/8/2006 3:59:52 PM
There are additional problems with sockets in threads; it makes it hard to shut the
threads down.  Asynchronous sockets are still the best bet.
					joe

On Fri, 8 Sep 2006 20:24:12 +0530, "jibesh" <jibesh.vp@gmail.com> wrote:

>why dont you try porting your socket connection code in a thread.
>
>Hav a try , and take rest :)
>
>- Jibesh
>
>"cybernerdsx2" <fongjengkum@gmail.com> wrote in message 
>news:1157703296.922842.178820@i3g2000cwc.googlegroups.com...
>> Hi,
>>
>> Okay, I switched to using CAsyncSocket now. But having the problem of
>> keeping the animated GIF to animate while waiting for some IP address
>> to timeout.
>>
>> Even if I try putting Sleep() after the call I still get the animated
>> GIF to hang.
>>
>> Do you know how I can do it?
>>
>>
>>
>>
>> Joseph M. Newcomer wrote:
>>> You are probably using CSocket, or synchronous sockets.  Don't do that. 
>>> The behavior you
>>> are seeing is expected.  Note that there are some network timeouts on the 
>>> order of 70
>>> seconds, so it is assumed that you will have arbitrarily long hangs.
>>>
>>> Use CAsyncSocket to do your work, then it won't hang.  Try to avoid raw 
>>> WinSock calls
>>> unless you enjoy being miserable.
>>> joe
>>>
>>> On 7 Sep 2006 02:34:48 -0700, "cybernerdsx2" <fongjengkum@gmail.com> 
>>> wrote:
>>>
>>> >Hi,
>>> >
>>> >I have a situation whereby when I call to the Winsock2's connect()
>>> >function, it takes a long time to respond back. This causes my
>>> >CPictureEx animated GIF to show hanging on the screen.
>>> >
>>> >I'm thinking of creating a thread for the connect() function call so
>>> >that it will not hang my animated GIF.
>>> >
>>> >Can anyone show me how to go about doing that?
>>> >
>>> >TIA.
>>> >
>>> >Rgds,
>>> >
>>> >Mike
>>> Joseph M. Newcomer [MVP]
>>> email: newcomer@flounder.com
>>> Web: http://www.flounder.com
>>> MVP Tips: http://www.flounder.com/mvp_tips.htm
>> 
>
Joseph M. Newcomer [MVP]
email: newcomer@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
0
newcomer (15975)
9/9/2006 12:36:55 AM
Reply:

Similar Artilces:

Office Update 10.2.3 kills network connections to shares.
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Don't ask me why, but I witnessed this myself. I just did a clean install on a 27&quot; iMac updated the OS to 10.6.2 set up several SMB shares and ran the final office update 10.2.1.(which I had disk images of) I left the clients place telling him to use the software update on MS Office for the remaining updates. He updated his Office to 10.2.3 and it killed the ability to connect to the shares I had already set up. I went back and tried to reconnect the shares and the &quot;Connect to Server&qu...

Timed recordings
I'm just about to start building my own media PC, which will primarily serve as a receiver and recorder for digital TV - both from satellite and terrestrial. I'm in the UK, but as the UK newsgroup for Media Center is rather quiet, I thought I'd seek help from both groups. I hope you don't mind the cross-posting. I can't remember the correct terminology, but our broadcasters send some sort of control signal along with the broadcast which indicates the precise start and stop times of each programme (this is in addition to the usual programme guide). It i...

Time Clock in RMS
We use the time clock feature in RMS and are, for the most part, happy with the results. Some of the issues we have with it are: We really do not want to give all employees that "punch the clock" the ability to sign on to POS but that seems to be a neccessity to use this feature. We would like to be able to attach a message to an employee that will pop-up when that employee attempts to punch in. Messages such as "see store manager when you arrive" or "W4 is due today" would be very helpful in communicating with each employee. Does anyone make a time cloc...

Time Calculation #3
...

Its time for release debugging
Hello. We have moved to release version of our products. I'm new to debugging release version. I guess there is an option to understand the reason for a crash in my application although it is a release version. Whenever there is a crash a pop-up window called "error report content" is displayed with "Send error" or something. I can view the stack on this window but I know nothing about using it. Where can I start from? I need any information on debugging/finding crash reason on release versions of my application. Thanks, Janiv Ratson. Would this crash be happeni...

Time allotment deduction in Contract Lines
Hi, I tried to use the contract in CRM to track SLA activities. I created a new template and set "Allotment Type" to "Time". However when I created a case with a service activity and completed (or resolved) both, the deduction was only 1 instead of actual minutes set in the service activity. I set the minutes of Contract Line to 120 and task took 1 hour (60 minutes). There has been some customizations and workflow done for Cases, not Contract. But I wouldn't have thought that would have mattered. Any enlightment is appreciated. Tony Hi Tony, I just tried the...

How to fix Run/time error 438
Hello In this forum Mr. Albert D. Kallal gently helped me with this piece of code to paste .pdf files on DeskTop Private SubtxtPath_Click() Dim strDeskTop As String 'get path location to desktop strDeskTop = CreateObject("Shell.Application").Namespace(&H10&).self.Path FileCopy "C:\Belly\DataBase\Docs\" & Me.txtPath, strDeskTop & "\" & Me.txtPath However, after clicking the button this messaged is displayed: Run-time error '438': Object doesn't support this property or method When I open the vba it shows in ye...

"Unable to connect to server" error 800ccc0e/800cccoe
I've gotten this error before, normally it means the server is unresponsive or non-existent. The problem I have is that I can ping the server, login using Horde (webmail) on the same server and-- worst of all-- can even use the server's I.P. address without any response. I also fail to send through any SMTP server, whether my own or my ISP's. I don't have Pc-Cillin installed, as the Outlook Support site suggested, but I am running Norton Antivirus. Is there anything else that could possibly cause this issue? Thanks! - Quiller quiller@equiller.com Try turning off ou...

Change colour once a certain time period passed
I record the date of when I send a letter. I send several hundred o these letters. Once 30 days passes, I need to send out a reminder t these people that receive the letters. I was thinking that perhaps th best way to do this would be to have the cells automatically chang colour to indicate that 30 days has passed. But as only a basi formula user in excel, whats the simpliest way to do this -- Diann ----------------------------------------------------------------------- Dianne's Profile: http://www.excelforum.com/member.php?action=getinfo&userid=3029 View this thread: http://www.e...

Sales Report filtered by time, Z Report filtered by date
Does anyone have any Z summary reports that can be filtered by day, week, etc Also does anyone have a sales summary report that can be filtered by date and time. (Our liquor store is open untill 1 AM and I can't get the broken out sales over the "two day" period once sales has started on the next day? Thank you so much in advance. There is a combined Z report on the Jean Holland web site (I believe) that does exactly what you want it to do. In regards to (sales) reports by date and time: I asked the same question a week or so ago in this NG but didn't get any soluti...

How do I hold email in Exchange Queue to be sent at specific time/date?
Our company is in the process of creating a weekly email newsletter/reminder to be sent out to subscribing customers. I'm using an account on our Exchange 2003 SP2 server to relay emails from our website to the customer. I want to be able to queue up and hold the emails for this account to be sent at a specific time, say Monday mornings at 8am, but I don't want to interfere with the normal operation of the rest of the organization's incoming/outgoing email. How do I go about doing this? I've looked at the SMTP Connectors and it appears as if this is possible, but I do...

Run-Time error '13': Type mismatch
Hi guys, I've got a spreadsheet that contains macros that remove columns and re-format the contents of a report. The idea is that the users copy the report (in xls format) and paste it in this workbook and run the macros by clicking on a button. My macros assume the first row contains the first record My users are not computer savvy and pasting the report in my spreadsheet by selecting any cell other than A1 will mean that my macros will pretty much butcher the report and the results will be useless. My solution was to unlock only cell A1 and protect the whole spreadsheet...

2003 org connected to 2003 org....but with same email addresses
Hi I am starting a domain migration, but ideally we want to setup users from scratch. Currently we have an exchange 2003 organisation, with front and backend servers, and we want to leave the mail flowing into that org during the staged migration.....we then want to create a new exchange environment on the new domain. The users will have the same email addresses. Will the ADC cope with this? so in essense mail will flow to to the old exchange server, but then if it doesn't find a account with the email address as I would have either deleted it or removed the SMTP address, I then need i...

can you force long lines of text to wrap width of cell?
should i do nothing or choose the wrap text option in the format cells dialog or click wrap text in the edit menu, or right click the cell and select wrap text help? Wrap text in the Format Cells dialog -- HTH RP "excel help" <excel help@discussions.microsoft.com> wrote in message news:18081AAF-FD5E-4FF4-BF77-EDFF43B74901@microsoft.com... > should i do nothing or choose the wrap text option in the format cells dialog > or click wrap text in the edit menu, or right click the cell and select wrap > text help? ...

Conversion Of Unix Time
Hi All, I have a field on my excel report which comes as a UnixTime (1235502582).I want this to be in Excel readable format for e.g 24- SEP-2009 21:20.The char is string type I want to use this in a macro,since affer the data is downloaded,i want the code to convert.The data is several thousand rows.How would I make a column reference to call the macro. If I am using a macro like , Public Function UnixTime2DT(lUnixTimeStamp As Long) As Date UnixTime2DT = DateAdd("s", lUnixTimeStamp, #1/1/1970#) End Function how would i call it to a particular column? I tried to call it as .Co...

Time-scale option
I can=B4t set up the time scale x axis of my line chart. If I click automatic options the scale show dates of 1900,=20 but I want to see the real months that are on my table.=20 The format of the table column is dd-mm-yy from 2002 to=20 2004 and I need to see in the chart these months, no 1900. If I type min and max dates, the lines are shrink into the=20 3 first month of 2002, so the don=B4t show the right=20 information, neither.=20 Thank you very much. Hi only some ideas: - are you really using date values in you table? Esp. showing 1900 in your chart indicates there may be a problem with...

Time field conversion to SQL 2000
I have an Access 2000 db that I want to upsize to SQL server 2000. Some fields are of date/time data type and show only time in hours and minutes, These fields will not convert. What should I do??? (Fields of date/time type that show short date will convert.) Thanks a M for your help. Magnus Add a phony date to them. Usually the system minimum is used. (Sometimes the max.) Depends on what you need. Once the data is stored in SQL Server you can still display just the hours and minutes. Actually, Access *does* store the date/time field with a date. So you may not be displaying it but i...

Appointment start time changed to one hour later in OWA
I currently have a problem with exchange server 2000 and OWA. When a client opens and accepts an appointment through OWA the appointment time is changed to be one hour later than the appointment time should be. I have found KB article 818379 which describes this problem, and says to install september post sp3 rollup. After applying these updates and re-booting the exchange server, the problem still exists. Has anyone come across this problem before? Our setup includes 5 exchange servers across 3 sites, with 2 sites having both a front-end and back-end exchange server. Both the front-end and ba...

CRM connection to subsidiary
Hi, we have introduced MS CRM with an own CRM Server. On this CRM Server we have also implemented a SQL Server. Additionally we use an own Exchange Server 2003 and Active Directory. In near future we face the CRM connection to our subsidiary which has to get access to our CRM system. They have their own Exchange Server 2003 but should - if possible - not have an own CRM Server. Has anyone experience regarding this problem and give us some advice? Is a CRM-connection to our subsidiary with these conditions possible? Thank you very much for your help!! Angela Hello Angela. This is Krish...

On Hand Quantity Point in Time
Ok, so I have figured out how to make a crystal report generate a on hand quantity for an item at any given time in the past. I have that now as a sub report and transfered the value in a variable to the main report to to perform other logic tasks but it has some issues. I can not sum or count any calculations for the report in total due to the nature in which the calculations are done so what I really need is someway for the SQL server to provide that answer. That is, given item X and date Y what was the quantity on hand on that day based on the sum of calculations and the adjusted be...

timeout error with Outlook 2000
I just installed Outlook 2000 on my computer & it cannot connect w/ my e-mail server. It gives me a tcp/ip timeout error. Outlook Express works fine, and all the settings are the same between the two. I am running McAfee Virus Scan, but i have tried disabling it, and it still doesnt work. can someone help PLEASE!!!!!! ...

Great Plains should allow setting an inactivity timeout
When anyone logged into Great Plains has been inactive for a prespecified period (e.g. 30 minutes) they should be automatically logged out of the application. ---------------- This post is a suggestion for Microsoft, and Microsoft responds to the suggestions with the most votes. To vote for this suggestion, click the "I Agree" button in the message pane. If you do not see the button, follow this link to open the suggestion in the Microsoft Web-based Newsreader and then click "I Agree" in the message pane. http://www.microsoft.com/Businesssolutions/Community/NewsGrou...

How to change appointment time for a series?
When I open a series I can not find a way to change the appointment time. When the appointment time changes for a series event, how do I change the appointment time for the series? Outlook 2003 Do you mean a "recurring appointment"? -- Kathleen Orland Blessed are the cracked, for it is they who let in the light Outlook Tips: http://www.outlook-tips.net/ http://www.howto-outlook.com/ "Bryan" wrote: > When I open a series I can not find a way to change the appointment time. > > When the appointment time changes for a series event, how do I change the ...

printing the saved date/time
is the a field code or something to print the save date in a footer i.e there is a field code for the current date in excel &[date], but i would like it to be the last date it was saved thanks in advance!!! You need VBA to do this If you copy this in the ThisWorkbook module it will print the Last Save Time in the RightFooter of every sheet you print Private Sub Workbook_BeforePrint(Cancel As Boolean) Dim wkSht As Worksheet For Each wkSht In ThisWorkbook.Worksheets wkSht.PageSetup.RightFooter = "&8Last Saved : " & _ ActiveWorkbook.BuiltinDoc...

Keeping 2 Excel workbooks open at the same time
I was able to have 2 workbooks open at the same time on a wide screen laptop, and somehow my settings must have gotten modified. Now I can only open 1 workbook at a time. Each time that I attempt to open a 2nd one, the first one is minimized. How do I correct this? Thanks for your help -- Royal How about just window|Arrange|Tiled (or whatever you want) Royal wrote: > > I was able to have 2 workbooks open at the same time on a wide screen laptop, > and somehow my settings must have gotten modified. Now I can only open 1 > workbook at a time. Each time that I attempt to open a...