473,785 Members | 2,283 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket State Question

Hi all,
Excuse me if this is wrong forum for this but I've implemented a
protocol handler for my socket server using the state pattern and it
works fine until I attempt to introduce heartbeats which are sent
independently of the client process on the same socket to the server.
Now the state can be processing commands and finds that it has received
a message for the client and this contravenes the protocol and state
transition is inconsistent.

So much for trying something new. What have other people used to solve
this?

It has been suggested that I use a seperate port on the same machine to
send heartbeats but, well, I want to know that that command socket is
responsive and alive.

Erm. thats it.

Ta

CJ

Nov 15 '06 #1
3 2110
"Court Jester" <co************ @hotmail.co.ukw rote in message
news:11******** *************@m 7g2000cwm.googl egroups.com...
Hi all,
Excuse me if this is wrong forum for this but I've implemented a
protocol handler for my socket server using the state pattern and it
works fine until I attempt to introduce heartbeats which are sent
independently of the client process on the same socket to the server.
Now the state can be processing commands and finds that it has received
a message for the client and this contravenes the protocol and state
transition is inconsistent.

So much for trying something new. What have other people used to solve
this?
Most people don't bother with "heartbeats ". You try sending, and if it
works, everything is okay. If you aren't sending, you don't care whether
the connection is valid at that moment. It could become valid by the next
time you actually need it, and so detecting that it's invalid at that moment
is counter-productive.

This oversimplifies a bit, but the bottom line is that it usually doesn't
make sense to intentionally cause an error to occur when none would
otherwise happen.

As far as your specific issue goes, well...the problem is entirely
architectural, within your own code. If you insist on using heartbeats,
then you need to build logic into your network code that can tolerate extra
communications occuring while you are "processing commands". The answer to
that has nothing to do with .NET or C#.

Pete
Nov 15 '06 #2
Are you communicating on your socket synchronously or asynchronously?
If you are using a synchronous pattern, one thing I have done in the
past is use the .DataAvailable attribute of the NetworkStream object
derived from the socket (I know, getting complicated). The idea was, if
there is no information available, go ahead and test the connection. To
test the connection I simply tried to send a predetermined "test
packet" over the connection, and if this attempt is placed in a
try/catch block then you'll know when the connection has been lost.

That said, as someone mentioned in this thread before, if you're not
using a socket you might not care if it's connected until you need it.
I guess it depends on what you're trying to do. Often times with
wireless networks, connections will be lost for a couple of seconds and
then regained. If during that time your app wasn't doing anything,
there's no reason to go through a bunch of connection lost code if the
connection will just be re-established before you're done dealing with
the fact you lost connection. Again, depends on your goals.

Hope this helps. If you think you need to see some sample code I could
do that with a better idea of your goals. Good luck!

Peter Duniho wrote:
"Court Jester" <co************ @hotmail.co.ukw rote in message
news:11******** *************@m 7g2000cwm.googl egroups.com...
Hi all,
Excuse me if this is wrong forum for this but I've implemented a
protocol handler for my socket server using the state pattern and it
works fine until I attempt to introduce heartbeats which are sent
independently of the client process on the same socket to the server.
Now the state can be processing commands and finds that it has received
a message for the client and this contravenes the protocol and state
transition is inconsistent.

So much for trying something new. What have other people used to solve
this?

Most people don't bother with "heartbeats ". You try sending, and if it
works, everything is okay. If you aren't sending, you don't care whether
the connection is valid at that moment. It could become valid by the next
time you actually need it, and so detecting that it's invalid at that moment
is counter-productive.

This oversimplifies a bit, but the bottom line is that it usually doesn't
make sense to intentionally cause an error to occur when none would
otherwise happen.

As far as your specific issue goes, well...the problem is entirely
architectural, within your own code. If you insist on using heartbeats,
then you need to build logic into your network code that can tolerate extra
communications occuring while you are "processing commands". The answer to
that has nothing to do with .NET or C#.

Pete
Nov 15 '06 #3
heartbeats should not effect any state in your client protocol. So process
them, but ignore them as far as your state machine. You heartbeat state can
be done on another thread and/or using timercallbacks, etc.

--
William Stacey [C# MVP]

"Court Jester" <co************ @hotmail.co.ukw rote in message
news:11******** *************@m 7g2000cwm.googl egroups.com...
| Hi all,
| Excuse me if this is wrong forum for this but I've implemented a
| protocol handler for my socket server using the state pattern and it
| works fine until I attempt to introduce heartbeats which are sent
| independently of the client process on the same socket to the server.
| Now the state can be processing commands and finds that it has received
| a message for the client and this contravenes the protocol and state
| transition is inconsistent.
|
| So much for trying something new. What have other people used to solve
| this?
|
| It has been suggested that I use a seperate port on the same machine to
| send heartbeats but, well, I want to know that that command socket is
| responsive and alive.
|
| Erm. thats it.
|
| Ta
|
| CJ
|
Nov 15 '06 #4

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

Similar topics

5
11726
by: mscirri | last post by:
The code below is what I am using to asynchronously get data from a PocketPC device. The data comes in fine in blocks of 1024 bytes but even when I send no data from the PocketPC constant blocks of 1024 with all values set to Null arrive. Other than examine a block of 1024 to see if the entire block is null, is there any other way to determine if , say a chat message "Hi Charlie" has been received completely?
2
2879
by: Rene Sørensen | last post by:
We are 4 students working on a assignment, that our teacher gave use, normally we do this is C++, but the 4 of us, use C# more often that C++ so… We made a small games called reversi, now our job is to make a server, none of us know nothing about socket programming in C#, but we founds some guides for this, and now ,got a server running, but we have some problems though. We have 2 scenario, one where we use a telnet connection and one...
7
2388
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?
2
1133
by: Marty | last post by:
Hi, I hope you can help me with this one (my code is below my message). I have many clients connecting to my server. When any of them disconnect, something happen. This user get disconnect from the server and this is fine. But sometime, I can't reproduce exactly the situation (maybe the client crashed), the related socket in server seems to get nuts and still think
9
3604
by: Macca | last post by:
Hi, I have a synchronous socket server which my app uses to read data from clients. To test this I have a simulated client that sends 100 byte packets. I have set up the socket server so that its buffer is bigger than this. I did this expecting the data to be read in one pass.
2
6879
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless there is a problem with the connection. I need to know which client has sent the incoming data as each client has its own buffer on my "server" app. I am using the standard asynch socket code from MSDN to listen for connections and they...
0
4690
by: Macca | last post by:
Hi, I am writing an asychronous socket server to handle 20+ simulataneous connections. I have used the example in MSDN as a base. The code is shown at end of question. Each connection has a number of different types of data coming in. I have a databuffer for each type of data coming in.
4
3605
by: Engineerik | last post by:
I am trying to create a socket server which will listen for connections from multiple clients and call subroutines in a Fortran DLL and pass the results back to the client. The asynchronous socket client and asynchronous socket server example code provided in the .NET framework developers guide is a great start but I have not dealt with sockets before and I am struggling with something. From what I can tell the sample server code ...
6
15613
by: billiejoex | last post by:
Hi there. I'm setting up test suite for a project of mine. situations, if the socket is closed on the other end or not. I noticed that I can "detect" such state if a call to socket.read() returns 0 but it seems a little poor to me. :-\ Is there a reliable way to test such socket 'state'?
2
3674
by: manasap | last post by:
Hi all! I've written a server and a client application using asynchronous sockets.The client sends data packets for every 7 seconds.The server receives the packets. This process proceeds smoothly without any errors but,sometimes I get the following error. "An existing connection was forcibly closed by the remote host." Why is this happening when i am not closing the client program? Could someone guide me in this issue
0
9489
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
10357
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
10162
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...
1
10101
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9959
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
8988
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
7509
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...
1
4063
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2893
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.