473,753 Members | 6,232 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asynchronous server isn't responding after second send

50 New Member
I based my program on the asynchronous client/server example on msdn. There weren't too many modifications to the original code. I just created some extra code to response to different messages. F.e. when I send GETARTICLES<EOF > it gets the articles from the DB and when I send something else it does that specific task. That all works fine. The problem is when I connect to the server and I try to send 2 commands after another. F.e. First get the articles, when that is done get the shippings or something. This would look like the following:

Expand|Select|Wrap|Line Numbers
  1.             if(!File.Exists(@"\System\products.xml"))   
  2.             {   
  3.                 Console.WriteLine("Requesting producs file");   
  4.                 Send("REQPRODUCTS|"+wh_id+"|<EOF>");   
  5.                 sendDone.WaitOne();   
  6.                 Receive();   
  7.                 receiveDone.WaitOne();   
  8.                 Console.WriteLine("Products file received");   
  9.             }   
  10.             else  
  11.             {   
  12.                 Response = "...products.xml already exists...";   
  13.                 Console.WriteLine("Products file exists");   
  14.             }   
  15.             if(!File.Exists(@"\System\shippings.xml"))   
  16.             {   
  17.                 Console.WriteLine("Requesting shippingslist");   
  18.                 Send("GETSHIPPINGSLIST|"+wh_id+"<EOF>");   
  19.                 sendDone.WaitOne();   
  20.                 Receive();   
  21.                 receiveDone.WaitOne();   
  22.                 Console.WriteLine("Shippingslist received");   
  23.             }   
  24.             else  
  25.             {   
  26.                 Response = "...shippings.xml already exists...";   
  27.                 Console.WriteLine("Shippingslist exists");   
  28.             }  
Now it does the first if correctly and then it enters the second if..It goes through every method (send, receive)
But the server doesn't react to anything at all. What could be the problem here? When I close the connection to the server and start the process, connecting etc all over again it works.
So I though it was a prolem in the server. I looked at the send process in the server. There I saw that the handler (the client connection) is shutdown, right?
So I tried several things. I commented out these lines and tried to call the beginReceive on the handler object. But this was not so succesful. After that I tried the following approach. But that also doesn't work. Because this is only caught when a new connection is made, right?

Expand|Select|Wrap|Line Numbers
  1.         private static void SendCallback(IAsyncResult ar)   
  2.         {   
  3.             try  
  4.             {   
  5.                 // Retrieve the socket from the state object.   
  6.                 Socket handler = (Socket)ar.AsyncState;   
  7.  
  8.                 // Complete sending the data to the remote device.   
  9.                 int bytesSent = handler.EndSend(ar);   
  10.                 Console.WriteLine("Sent {0} bytes to client.", bytesSent);   
  11.  
  12.                 handler.Shutdown(SocketShutdown.Both);   
  13.                 handler.Close();   
  14.  
  15.                 //I thought the following would solve the problem but it didn't   
  16.                 //Start accepting again   
  17.                 listenerSock.BeginAccept(   
  18.                         new AsyncCallback(AcceptCallback),   
  19.                         listenerSock);   
  20.  
  21.             }   
  22.             catch (Exception ex)   
  23.             {   
  24.                 Console.WriteLine("Error while sending: "+ ex.Message);   
  25.             }   
  26.         }   
Can anyone please help me?
Oct 15 '08 #1
2 1547
mldisibio
190 Recognized Expert New Member
Please note well: I have zilch experience with asynchronous socket communication.

However, I do see that in the notes for Socket.Shutdown , the Shutdown.Both value completely disables sending/receiving on that socket. The remarks indicate: "Do not attempt to reuse the Socket after closing."

I am not sure what the process is to re-enable a disabled socket, but it sounds like your program is working fine, but after the first batch of commands, the socket is closed and will not be re-enabled until you restart the process.

Check out the notes for using Close without Shutdown. There is an option to block the close until the outgoing data is sent.

Again, I know next to nothing about Sockets, but probably the MSDN example assumed only one send/receive. Probably if you want multiple send/receives, you would want to shutdown the socket only after all communications are finished.
Oct 16 '08 #2
SvenV
50 New Member
Thank you for your response. Yes I also thought that was the problem so I disabled this piece of code without result. I'll do some more investigating on those properties and let you know.
Oct 17 '08 #3

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

Similar topics

6
2935
by: Zunbeltz Izaola | last post by:
Hi, I have the following problem. I'm developing a GUI program (wxPython). This program has to comunicate (TCP) whit other program that controls a laboratory machine to do a measurement. I have a dialog box, wiht two buttoms "Start measurement" and "Stop". "Start" executes a function that do the measurement in the following way.
15
4490
by: Michael Rybak | last post by:
hi, everyone. I'm writing a 2-players game that should support network mode. I'm now testing it on 1 PC since I don't have 2. I directly use sockets, and both client and server do computations, the only data transfered is user mouse/kbd input. It works synchronously, but somehow, when I play in client window, both client and server have 17 fps, while when playing in server window, server has 44 fps while client ...
5
9848
by: Jeff Weber | last post by:
First, my question: Should I use Write or BeginWrite (sync or async) to stream data to my clients over a TCPClient connection. Details: On the server I have a custom circular data buffer that receives byte array data representing data structures at a rate of 30ms. On a thread seperate from that which Enqueues data to the buffer I have a high performance timer that Dequeues data from the custom buffer and sends it via a tcpClient...
0
1557
by: Kruz | last post by:
Somewhere around 500 connections when calls (BeginSend calls) are arround 108,752 and total bytes sent are around 9,496,399 bytes - send callbacks (EndSend) stop coming in C# asynchronous sockets. I'm counting how many BeginSend are issued and how many EndSend are received, and somewhere around 500 connections send callbacks stop coming even when the count for BeginSend shows that there are pending sends in the system. Here is the...
0
1673
by: Jonathan Trevor | last post by:
Hi, I've found what appears to be a bug with ASP.NET web service method invocation - making it impossible to invoke and get the result of a synchronous web call after an asynchronous call has been made if both are using sessions. Heres an example for two calls in the web service, the first is expected to be executed asynchronously by the client and the second to get the progress of the first while it is executing:
7
2385
by: Colin | last post by:
I'm writing a little console socket server but I'm having some difficulty. Can I ask your advice - where is the best place to get some help on that topic? It would be nice if some people who knew what they were doing could take a look at my code and tell me where and why I'm going wrong. Any suggestions of groups or forums?
4
2767
by: Macca | last post by:
I am writing an application that uses asynchronous sockets to get data over ethernet from embedded devices, up to 30 concurrent devices.(These devices are written in C). My application implements an asychronous socket server while the embedded devices are the clients When the data comes in over the socket it is eventually passed into a message queue.
5
15510
by: HugeBob | last post by:
Hi All, I've got a question about Asynchronous vs Synchronous mode with the XMLHttpRequest object. What are the ramifications of using one mode vs the other? If the script uses Asynchronous mode, it sounds as if a thread retrieves the data from the supplied URL and the JS function that called the open() and send() methods continues on. Where as using Synchronous mode the method that called open() and send() waits until the data from...
0
1564
Frinavale
by: Frinavale | last post by:
I have a peculiar problem... Background: I have a function that I don't want the user to execute more than once while they are waiting for it to process; therefore, I disable all of the controls on the page via some JavaScript before the request is sent. This function takes some time to execute because it has to communicate with hardware that is rather slow. This slowness combined with a little bit of lag sometimes results in a ...
0
8896
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9653
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
9451
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
9333
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
8328
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
6869
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
6151
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
4771
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...
3
2284
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.