473,503 Members | 2,322 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Regarding shared memory

Dear all,

I have a server program that listens to a particular port and a number
of client programs that connect to the server.

Now i want to put some data in form of python list in main memory on
server.Hence whenver a client program is run it connects to the server
and access the data in main memory.Here the server calls a module that
processes the data as per the client request and the returns some
information to the client.

I can create client and server programs using socket programming,but i
am not able to put the data in shared memory and then access it.

NOTE:I want to put the data in main memory only once(on the server
using server program) i.e. whenever client connects to the server it
should only access the data and not create a replica of data already
loaded in memory.How can this be achieved

thanks.
Oct 30 '08 #1
2 1663
On Thu, Oct 30, 2008 at 2:13 PM, gaurav kashyap <ga***********@gmail.comwrote:
Dear all,

I have a server program that listens to a particular port and a number
of client programs that connect to the server.

Now i want to put some data in form of python list in main memory on
server.Hence whenver a client program is run it connects to the server
and access the data in main memory.Here the server calls a module that
processes the data as per the client request and the returns some
information to the client.

I can create client and server programs using socket programming,but i
am not able to put the data in shared memory and then access it.

NOTE:I want to put the data in main memory only once(on the server
using server program) i.e. whenever client connects to the server it
should only access the data and not create a replica of data already
loaded in memory.How can this be achieved
This is trivially done with an event-driven framework
such as Twisted or Circuits. I'm the author of circuits (1.0
release coming soon), so here is a circuits based example:

Server code:
<code>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set sw=3 sts=3 ts=3

"""(Example) Echo Server

A simple Echo Server example that sends back to connected clients
the input the server receieves.

This example demonstrates:
* Basic Component creation.
* Basic Event handling.
* Basic TCP Server

This example makes use of:
* Component
* Event
* Manager
* lib.sockets.TCPServer
"""

from circuits.lib.sockets import TCPServer
from circuits.core import listener, Event, Component, Manager

###
### Components
###

class EchoServer(TCPServer):

def __init__(self, *args, **kwargs):
super(EchoServer, self).__init__(*args, **kwargs)

self.data = [1, 2, 3, 4]

@listener("read")
def onREAD(self, sock, data):
self.write(sock, data)
self.write(sock, "Data: %s" % self.data)

###
### Main
###

def main():
manager = Manager()
server = EchoServer(8000)
manager += server

while True:
try:
manager.flush()
server.poll()
except KeyboardInterrupt:
break

###
### Entry Point
###

if __name__ == "__main__":
main()
</code>

Client code: (I'm just using a basic telnet example here)
<code>
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set sw=3 sts=3 ts=3

"""(Example) Telnet Client

A basic telnet-like clone that connects to remote hosts
via tcp and allows the user to send data to the remote
server.

This example demonstrates:
* Basic Component creation.
* Basic Event handling.
* Basiv Networking
* Basic Request/Response Networking

This example makes use of:
* Component
* Event
* Manager
* lib.sockets.TCPClient
"""

import optparse

from circuits.lib.io import Stdin
from circuits.lib.sockets import TCPClient
from circuits import __version__ as systemVersion
from circuits.core import listener, Event, Component, Manager

USAGE = "%prog [options] host [port]"
VERSION = "%prog v" + systemVersion

###
### Functions
###

def parse_options():
"""parse_options() -opts, args

Parse any command-line options given returning both
the parsed options and arguments.
"""

parser = optparse.OptionParser(usage=USAGE, version=VERSION)

parser.add_option("-s", "--ssl",
action="store_true", default=False, dest="ssl",
help="Enable Secure Socket Layer (SSL)")

opts, args = parser.parse_args()

if len(args) < 1:
parser.print_help()
raise SystemExit, 1

return opts, args

###
### Components
###

class Telnet(TCPClient):

@listener("connect")
def onCONNECT(self, host, port):
print "Connected to %s" % host

@listener("read")
def onREAD(self, data):
print data.strip()

@listener("stdin:read")
def onINPUT(self, data):
self.write(data)

###
### Main
###

def main():
opts, args = parse_options()

host = args[0]
if len(args) 1:
port = int(args[1])
else:
port = 23

manager = Manager()

telnet = Telnet()
stdin = Stdin()

manager += stdin
manager += telnet

print "Trying %s..." % host
telnet.open(host, port, ssl=opts.ssl)

while telnet.connected:
try:
manager.flush()
stdin.poll()
telnet.poll()
except KeyboardInterrupt:
break

telnet.close()

###
### Entry Point
###

if __name__ == "__main__":
main()
</code>

Client output:
<paste>
$ ./telnet.py localhost 8000
Trying localhost...
Connected to localhost
test
test
Data: [1, 2, 3, 4]
</paste>

Circuits can be downloaded from:
http://trac.softcircuit.com.au/circuits/

cheers
James

--
--
-- "Problems are solved by method"
Oct 30 '08 #2
On Oct 29, 11:13*pm, gaurav kashyap <gauravkec2...@gmail.comwrote:
Dear all,

I have a server program that listens to a particular port and a number
of client programs that connect to the server.

Now i want to put some data in form of python list in main memory on
server.Hence whenver a client program is run it connects to the server
and access the data in main memory.Here the server calls a module that
processes the data as per the client request and the returns some
information to the client.

I can create client and server programs using socket programming,but i
am not able to put the data in shared memory and then access it.

NOTE:I want to put the data in main memory only once(on the server
using server program) i.e. whenever client connects to the server it
should only access the data and not create a replica of data already
loaded in memory.How can this be achieved

thanks.
Shared memory is available in the 'mmap' module. However, you can't
share a Python list object between processes. The closest you can do
is share a ctypes.Array or struct.Struct.
Oct 30 '08 #3

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

Similar topics

0
4356
by: Srijit Kumar Bhadra | last post by:
Hello, Here is some sample code with pywin32 build 203 and ctypes 0.9.6. Best regards, /Srijit File: SharedMemCreate_Mutex_win32all.py # This application should be used with...
0
1503
by: Ron Ben-Natan | last post by:
Hi, Local clients talking to the server do so over the shared memory net-library. As far as I understand they use a shared memory segment and an event to signal each other when data is ready....
3
2117
by: alanrn | last post by:
I would like to start a dialog on how to implement the equivalent functionality of UNIX shared memory in .NET. I work with a factory automation system. The bulk of the system is written in C/C++....
11
4863
by: Michael Schuler | last post by:
The use of STL in shared memory poses a real problem since (non-smart) pointers are not allowed there. Is there any solution for containers in shared memory using smart pointers? Where can I...
1
2103
by: myren, lord | last post by:
When I first discovered shared memory (between multiple processes) I immediately started thinking of how to build my own VM subsystem + locking mechanisms for a large single block of memory. This...
14
8175
by: phil_gg04 | last post by:
Dear C++ Experts, Over the last couple of months I have been writing my first program using shared memory. It has been something of an "in-at-the-deep-end" experience, to say the least. At...
12
5508
by: Jeremy | last post by:
Hi all, I'm getting very confused about how DB2 uses shared memory and I wonder if someone could clarify matters for me, please ? We are running 32bit DB2 V7.2 FP9 under AIX 4.3.3 on a machine...
5
7043
by: Jim | last post by:
Hello, I have a broken server that we are going to be moving off to a new server with a new version of DB2 but here is what I have right now: RedHat 7.0 (2.2.24smp) DB2 v6.1.0.40 I am...
10
627
by: Oriane | last post by:
Hello, I have to share a object in RAM between several processes. I intend to design a special process to load this objet (an Autocad plan) in memory, and to take care of the read/write...
0
7093
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...
0
7357
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...
0
7468
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...
0
5598
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,...
1
5023
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...
0
4690
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...
0
3180
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...
0
3171
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1522
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 ...

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.