473,503 Members | 1,639 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Socket sample?

I'm a newcomer to socket programming... I need to use a server socket
which should be able to handle more than one connection at a time. I've
read the HOWTO, but I'm still a bit confused about some of the more
intimate details. I've also seen a few pieces of sample code scattered
here and there, but nothing substantial.
Does anyone know of some sample code that handles multiple connections
(either by using select() or forking/threading processes)?
Thanks very much!

--Daniel

Jul 18 '05 #1
4 2303
Daniel Orner wrote:
I'm a newcomer to socket programming... I need to use a server socket
which should be able to handle more than one connection at a time. I've
read the HOWTO, but I'm still a bit confused about some of the more
intimate details. I've also seen a few pieces of sample code scattered
here and there, but nothing substantial.
Does anyone know of some sample code that handles multiple connections
(either by using select() or forking/threading processes)?
Thanks very much!


use twisted - its well worth the effort, and supports the things you need.

--
Regards,

Diez B. Roggisch
Jul 18 '05 #2
Hmm... I'm looked at the SocketServer, but I'm pretty confused about
how to use it. As far as I can tell it doesn't actually do any
forking/threading/selecting at all. There's a lot of generic stuff which
seems to allow that behavior for subclasses, but I can't see any
specific code that does that kind of thing. Or maybe I'm just missing
something stupendously obvious. If so, would you be so kind as to give
me a quick example of how it would be used?
I also took a quick look at twisted... it looks like it's way too
complex for what I have in mind. -_- Basically, I just want a socket to
transfer information to/from a client program, essentially to
synchronize data between the server and the client. The program is run
automatically (no user input). However, I do want it to be fast, which
means no waiting for a connection. That's why I just want to see some
sample code about how to use a server socket.
Any help would be greatly appreciated!

--Daniel

Jul 18 '05 #3
Daniel Orner wrote:
Hmm... I'm looked at the SocketServer, but I'm pretty confused about
how to use it. As far as I can tell it doesn't actually do any
forking/threading/selecting at all. There's a lot of generic stuff which
seems to allow that behavior for subclasses, but I can't see any
specific code that does that kind of thing. Or maybe I'm just missing
something stupendously obvious. If so, would you be so kind as to give
me a quick example of how it would be used?


The SocketServer docs say:
"The solution is to create a separate process or thread to handle each request; the
ForkingMixIn and ThreadingMixIn mix-in classes can be used to support asynchronous
behaviour. "

And if you look in SocketServer.py (from python 2.3.3) you'll see at line 479:

class ForkingUDPServer(ForkingMixIn, UDPServer): pass
class ForkingTCPServer(ForkingMixIn, TCPServer): pass

class ThreadingUDPServer(ThreadingMixIn, UDPServer): pass
class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass
So it already defines 4 specialized server classes for you to use :-)
Threading, or forking, whatever suits you best.
If you want a TCP server that uses a new thread for each request,
just use SocketServer.ThreadingTCPServer instead of
SocketServer.TCPServer and you're done!

--Irmen
Jul 18 '05 #4
Ah, I see! I didn't understand what those classes were doing. Thanks
very much!

--Daniel
The SocketServer docs say:
"The solution is to create a separate process or thread to handle each
request; the ForkingMixIn and ThreadingMixIn mix-in classes can be used
to support asynchronous behaviour. "

And if you look in SocketServer.py (from python 2.3.3) you'll see at
line 479:

class ForkingUDPServer(ForkingMixIn, UDPServer): pass
class ForkingTCPServer(ForkingMixIn, TCPServer): pass

class ThreadingUDPServer(ThreadingMixIn, UDPServer): pass
class ThreadingTCPServer(ThreadingMixIn, TCPServer): pass
So it already defines 4 specialized server classes for you to use :-)
Threading, or forking, whatever suits you best.
If you want a TCP server that uses a new thread for each request,
just use SocketServer.ThreadingTCPServer instead of
SocketServer.TCPServer and you're done!

--Irmen

Jul 18 '05 #5

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

Similar topics

0
2326
by: anuradha.k.r | last post by:
hi, I 'v e written both the server and client side socket programs in perl( a very small one).My socket is created and shows that the connection is established with the client.however I am not...
1
6139
by: Chan | last post by:
Building an Asyc Socket DLL using C#, I followed MS .NET FRAMEWORK library sample (see "Asynchronous Client Socket Example") and created a DLL called MSSock. I then reference MSSock in a .exe c#...
5
11641
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...
2
4135
by: Nuno Magalhaes | last post by:
I've got a simple problem I guess. How do I know when a connection is terminated without losing any data? I do something like the code below, but sometimes between socket.Receive and socket.Send...
10
4001
by: Uma - Chellasoft | last post by:
Hai, I am new to VB.Net programming, directly doing socket programming. In C, I will be able to map the message arrived in a socket directly to a structure. Is this possible in VB.Net. Can...
9
5510
by: zxo102 | last post by:
Hi everyone, I am using a python socket server to collect data from a socket client and then control a image location ( wxpython) with the data, i.e. moving the image around in the wxpython frame....
3
4261
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
4
3590
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...
8
4664
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi all, I am new to .net technologies. ASP.NET supports socket programming like send/receive in c or c++? I am developing web-site application in asp.net and code behind is Visual C#. In...
2
3642
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...
0
7084
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
7278
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,...
0
7328
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...
1
6991
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...
0
5578
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
5013
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
4672
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
3167
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...
1
736
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.