473,586 Members | 2,491 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Question re client/server and blocking

Hi all

I am developing a multi-user business/accounting application. It is
coming along nicely :-), though rather slowly :-(

I have hit an issue which will require a lot of changes to the code I
have written so far, together with an increase in complexity and all
the bad things that follow from that. Before I go ahead and make the
changes, I thought I would bounce it off the group and see if there is
a simpler approach.

It is a bit tricky to explain (yes I have read the Zen of Python) but
here goes.

There is a server component and a client component. All the business
logic is performed on the server. The client communicates with the
server via a socket. The server is multi-threaded - one thread per
connection.

The server receives messages from the client, and responds as quickly
as possible. Sometimes it must respond by asking the client a question.
It must not block while waiting for an answer, so this is how I handle
it (pseudo code) -

def handleMessage(s elf):
mainloop.askQue stion(questionT ext,self.answer Yes,self.answer No)

def answerYes(self) :
handle Yes answer

def answerNo(self):
handle No answer

The main loop stores the function references, and sends the question to
the client. When it gets a reply, it calls the appropriate function. It
works well.

The server performs field-by-field validation - it does not wait for
the entire form to be submitted, but validates the data as soon as it
has been entered. Depending on the context, the validation may have to
pass a number of checks, which may pass through a number of layers,
eventually returning True or False. e.g. -

def validate(self,d ata):
if not check1:
return False
if not check2:
return False
if not self.check3(dat a):
return False
if not self.check4(dat a):
return False
if not check5:
return False
return True

check3(self,dat a):
if not check3a:
return False
return True

check4(self,dat a):
if not check4a:
return False
if not self.check4b(da ta):
return False
return True

Effectively the entire chain blocks until a result is returned, but
provided each element performs its check quickly, this will not be
noticeable.

Now I have decided that, in some circumstances, I want the server to
ask the client a question before returning True or False - it could be
as simple as "Are you sure?". This throws a large spanner into the
above scheme. Each caller cannot be sure whether the callee (?) will
return quickly or not, so it cannot afford to wait for a reply,
otherwise it may block. The only solution I can think of looks like
this -

def validate(self,d ata,checkOk,che ckNotOk):
# checkOk and checkNotOk are functions passed by the caller
self.data = data
self.checkOk = checkOk
self.checkNotOk = checkNotOk
if not check1:
self.checkNotOk ()
if not check2:
self.checkNotOk ()
self.check3(sel f.data,self.che ck3Ok,self.chec kNotOk)

def check3Ok(self):
self.check4(sel f.data,self.che ck4Ok,self.chec kNotOk)

def check4Ok(self):
if not check5:
checkNotOk()
self.checkOk()

The callee must then look like this -

def check3(self,dat a,checkOk,check NotOk):
if check ok:
checkOk()
else:
checkNotOk()

Then on the odd occasion that the callee needs to ask a question, it
can do this -

def check4(self,dat a,checkOk,check NotOk):
mainloop.askQue stion(questionT ext,checkOk,che ckNotOk)

This is similar to Twisted's approach of deferreds and callbacks.
However, I do not think that using Twisted would simplify any of this -
I would still have to split my logic chain up into multiple callback
functions.

I believe that I can get this to work, that it will add a powerful
layer of functionality to my app, and that I could eventually refactor
it enough so that it is actually understandable. On the other hand, it
is much more complex than what I have got at present, and to change my
entire app to use this mechanism will be quite a task.

Have I explained myself adequately? Has anyone come across a similar
situation before? Any advice will be much appreciated.

Thanks

Frank Millman

Mar 5 '06 #1
1 1333
Frank Millman wrote:
[...]
There is a server component and a client component. All the business
logic is performed on the server.
Oh, what a give-away. If the logic is in the server, then the
client component should probably be the user's chosen web browser.

The client communicates with the
server via a socket. The server is multi-threaded - one thread per
connection.

The server receives messages from the client, and responds as quickly
as possible. Sometimes it must respond by asking the client a question. [...]
The server performs field-by-field validation - it does not wait for
the entire form to be submitted, but validates the data as soon as it
has been entered.
The modern way is to let the browser do the first cut at
validation and confirmation. Upon submit, the server
re-validates for security.

[...] Now I have decided that, in some circumstances, I want the server to
ask the client a question before returning True or False - it could be
as simple as "Are you sure?".
Simple checks such as "are you sure" can almost always be handled at
the browser. Nevertheless, the problem you note is quite real...
This throws a large spanner into the
above scheme. Each caller cannot be sure whether the callee (?) will
return quickly or not, so it cannot afford to wait for a reply,
otherwise it may block. The only solution I can think of looks like
this -


Right. The server should go into a state where it can accept
the answer, among other things. Building interactive apps that
don't suck requires some sophistication in managing state.
--
--Bryan
Mar 6 '06 #2

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

Similar topics

4
6574
by: Prince Kumar | last post by:
I joined a company recently and they have a java program which hangs (does nothing) after a while. This is no way consistent. It could succeed quite a few times and can fail a few other times. There is no consistency when it fails. Could anyone here shed some light on how to debug/resolve the issue. I guess IBM looked at the issue and were...
14
2170
by: Steve Jorgensen | last post by:
I just got paid to solve this problem for one client, so I might be impeding future business opportunities by sharing this secret, but a rising tide floats all boats, so... I've seen this mysterious problem now in many Access C/S applications. Usually some random GUI or workflow changes make the problem, but for at least one of my clients,...
3
2479
by: Matthew King | last post by:
Hi all I've written a asynchronous socket client class, but i've found that in order to consume it I have to use events, and cannot simply for example SocketClient client = new SocketClient(110, "some.server.com") client.Connect() client.SendData("Hello World") Instead I have to wait for the async method to raise a Connected event, and...
1
245
by: John | last post by:
Hi I have some difficulties understanding some issues with multithreading: *What is the meaning of: "implement a method to run each update call in its own thread" *If i have a component that does an AsynchronousCallBack that will pass data to the client, which thread will process the data, the caller or the client ? *How can know which...
1
1543
by: Brian Henry | last post by:
Hello, I was tring to learn socket's (being i never used them before) and have a simple question. I want to create a listner that will get any data recieved and print it out. I've been able to get it to recieve only one line of data, but the next one i send to it wont be printed like the 1st one. I had a listner running in a thread, does...
13
28731
by: Sandeep Singh | last post by:
I am making socket client application in C# how can i get ip address of client who has connected to server
14
4438
by: Ankit Aneja | last post by:
The code of classes given below is for server to which clients connect i want to get ip address of client which has connected pls help how can i get //listen class public class listen {
8
9566
by: Brian Tkatch | last post by:
Server: DB2/SUN 8.1.6 Client: DB2 Connect Personal Edition (No 11) <URL:ftp://ftp.software.ibm.com/ps/products/db2/fixes2/english-us/db2winIA32v8/fixpak/FP11_WR21365/FP11_WR21365_CONPE.exe> Uninstalled old version, installed new version, and am now trying to use the CLP. <<<<<<<<<<<< For more detailed help, refer to the Online Reference...
0
1566
by: =?Utf-8?B?UmFqbmk=?= | last post by:
Dear William Stacey, I have written a server code using the Windows Socket API's. Wherein I have created the socket and bound it to a particular IP address and port number. Later I have made the socket in non-blocking mode by using the proper socket option ( i.e. SO_RCVTIMEO). After which with the use of recv() I am trying to get into the...
0
7915
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7841
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...
0
8204
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. ...
0
8339
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...
1
7965
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...
0
8220
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...
0
6617
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...
1
5712
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...
1
1452
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.