473,320 Members | 1,857 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.

Disconnecting from server

Hie Team.

I am having this problem:
I am developing an application that is connecting to a server, the problem is when the server is not responding, the application wont allow me to do anything so i end up restarting the machine,

i am receiving data using the receive function as follows
Expand|Select|Wrap|Line Numbers
  1. nData = recv( hServer, &wzRec[iPos], nLeft, 0 );
  2.  
please help

thanks in advance
Oct 21 '11 #1
2 2033
johny10151981
1,059 1GB
I search on google about your problem.

I got one commmon solution it says using select() function before using receive

another solution i got a forum is more interesting
Expand|Select|Wrap|Line Numbers
  1.    { /* this block is just after the return from the socket() call and before connect() */
  2.             struct timeval tv; /* timeval and timeout stuff added by davekw7x */
  3.             int timeouts = 0;
  4.             tv.tv_sec = 3;
  5.             tv.tv_usec = 0;
  6.             if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, (char *)&tv,  sizeof tv))
  7.             {
  8.               perror("setsockopt");
  9.               return -1;
  10.             }
  11.  
  12.             if (connect(sockfd, (struct sockaddr *)&their_addr, sizeof their_addr) == -1) {
  13.                 perror("connect");
  14.                 exit(1);
  15.             }
  16.  
  17.             while (((numbytes=recv(sockfd, buf, MAXDATASIZE-1, 0)) == -1) && (++timeouts < 1000)) { /* loop to retry in case it timed out; added by davekw7x */
  18.                 perror("recv");
  19.                 printf("After timeout #%d, trying again:\n", timeouts);
  20.             }
  21.             printf("numbytes = %d\n", numbytes);
  22.  
  23.             buf[numbytes] = '\0';
  24.  
  25.             printf("Received: %s",buf);
  26.         }
  27.  
if you want to see the entire thread follow the link
Oct 21 '11 #2
hie johny

do yu have any idea on how to use this code for that problem above
Expand|Select|Wrap|Line Numbers
  1. struct timeval tv;
  2.  
  3.   tv.tv_sec = 3;  // 1 Secs Timeout 
  4.  
  5.   setsockopt(hServer, SOL_SOCKET, SO_RCVTIMEO,(char*)&tv,sizeof(struct timeval));
  6.  
I would be very grateful if you would tel me where exactly to put the code like what you told me in your first reply

I am having problems with your first code its not doing any thing at the moment.
THANKS
Oct 21 '11 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Nathan Sokalski | last post by:
I want to set up SQL Server on Windows XP Pro so that I can use the database capabilities of ASP and IIS. I am probably using some incorrect settings, but I am not sure what they are. Here is what...
4
by: banz | last post by:
Hello I have a problem to resolve: I wrote a Perlscript which caches data from a server (local on my machine) I would like to have a other connection to a remote server but I don't know how to...
7
by: Andreas Håkansson | last post by:
Hello, I'm building a small TCP based server which uses the Async commands. When a new connection is made to the server, I store the new socket in a hashtable, using the client IP as the key. ...
0
by: amita | last post by:
I have a Client (a TcpClient object) established connection with the Server(a TcpListener). I want that when the Server goes down, the TcpClient detects this disconnection and when the Server is back...
13
by: Joner | last post by:
Hello, I'm having trouble with a little programme of mine where I connect to an access database. It seems to connect fine, and disconnect fine, but then after it won't reconnect, I get the error...
4
by: coosa | last post by:
Hi, I was installing SQL Server on my machine and during installation my PC freezed. It happens frequently on my machine. So i tried after restarting to install it again and since then i always...
1
by: salvagedog | last post by:
We use xp_smtp_sendmail for all emailing from SQL Server. Occasionally it fails, generating the following message: Error: disconnecting from server mail.mydomain.com failed The failures are...
3
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi All, I have a ASP/C# application that connect to Oracle database . After issuing my SQL query if I close the browser or move into another page ( ie whle executing in the databse serevr) will...
6
by: jsacrey | last post by:
Hello everybody, I've got a bit of a situation that I could use some guidance with if possible. I work for an auditing firm where my users audit electronic shipping data for customers to see if...
0
by: Ontrace | last post by:
hello, I have Problem with Client Server Application when I unplug the client network cable, the server still read the network stream what function should I use to make server detect that the...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
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...

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.