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: - if(!File.Exists(@"\System\products.xml"))
-
{
-
Console.WriteLine("Requesting producs file");
-
Send("REQPRODUCTS|"+wh_id+"|<EOF>");
-
sendDone.WaitOne();
-
Receive();
-
receiveDone.WaitOne();
-
Console.WriteLine("Products file received");
-
}
-
else
-
{
-
Response = "...products.xml already exists...";
-
Console.WriteLine("Products file exists");
-
}
-
if(!File.Exists(@"\System\shippings.xml"))
-
{
-
Console.WriteLine("Requesting shippingslist");
-
Send("GETSHIPPINGSLIST|"+wh_id+"<EOF>");
-
sendDone.WaitOne();
-
Receive();
-
receiveDone.WaitOne();
-
Console.WriteLine("Shippingslist received");
-
}
-
else
-
{
-
Response = "...shippings.xml already exists...";
-
Console.WriteLine("Shippingslist exists");
-
}
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? - private static void SendCallback(IAsyncResult ar)
-
{
-
try
-
{
-
// Retrieve the socket from the state object.
-
Socket handler = (Socket)ar.AsyncState;
-
-
// Complete sending the data to the remote device.
-
int bytesSent = handler.EndSend(ar);
-
Console.WriteLine("Sent {0} bytes to client.", bytesSent);
-
-
handler.Shutdown(SocketShutdown.Both);
-
handler.Close();
-
-
//I thought the following would solve the problem but it didn't
-
//Start accepting again
-
listenerSock.BeginAccept(
-
new AsyncCallback(AcceptCallback),
-
listenerSock);
-
-
}
-
catch (Exception ex)
-
{
-
Console.WriteLine("Error while sending: "+ ex.Message);
-
}
-
}
Can anyone please help me?
2 1547
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.
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.
Sign in to post your reply or Sign up for a free account.
Similar topics |
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.
|
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 ...
|
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...
|
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...
|
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:
| |
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?
|
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.
|
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...
|
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 ...
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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();...
|
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...
| |
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...
| |