473,804 Members | 3,108 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Sockets programming

I've been following a socket programming tutorial to make a simple TCP
communication program, seemingly without hitches, it appears to work fine.
However the structure of it is to have a server listening for requests from
a client using listen(), and when one connects, it communicates with that
client but only that one. It doesn't listen for more requests.

What I'm wondering is can I have a server that continually listens for
requests from multiple clients, and when *any* client connects, it can
communicate with that client. I'm thinking multithreading is obviously going
to be necessary in some form, but basically my questions are:

1) Can the server use a method similar to that described in the second
paragraph above to communicate with multiple clients at the same time on the
same port, or does it have to use a different port for each client that's
simultaneously communicating?
My initial hunch tells me that I can - because a web server can do it, but
is there anything special to watch out for such as how it has to integrate
with (2),...

2) Is it necessary to have multithreading, e.g. the server spawns a new
thread for each client that connects in order to communicate with that
client.

Sorry if I've overly crossposted but this seems to be relevant to MS C++ and
standard C++ as I'm intending to use it in linux aswell as windows, (the
only thing seemingly different in linux seems to be that it has different
includes and doesn't have to call WSAStartup).

Jul 22 '05
11 2216
That may be true, but the true power of select() is seen when multiple
sockets are in use; testing FD_ISSET usually gets the job done quickly
for me. Implementations using select() for input polling usually
involve a very short loop no matter how many input sources exist, as
opposed to the monstrosities that can result from repeated usage of
accept()/fork(). select() also allows you to easily set a timeout value
on each socket. One problem worth mentioning about select(), though, is
that many sockets can be operating in the same process space. You must
be wary of shared resource usage when programming with select(),
whereas with fork(), no such precautions need to be taken. The question
you need to ask yourself before developing a socket based daemon is, as
it usually is, what is the intended use of your program? If it's going
to be servicing many concurrent requests and queueing requests is not
reasonable, using select() is probably the better solution. If not,
using accept()/fork() may prove to be easier.

-dave

Jul 22 '05 #11
dave windsor wrote:
That may be true, but the true power of select() is seen when multiple sockets are in use;

Please learn to quote properly on usenet. See the following for
assistance:
http://groups-beta.google.com/group/...9e82ab0843783d

Brian

Jul 22 '05 #12

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

Similar topics

1
2398
by: jubi | last post by:
I am trying to program for a PocketPC using C#. I know it is possible for sockets programming for a desktop using C#. I'd like to know if it's possible to: 1. Sockets programming for the PocketPC and 2. Using C# Links to more reading/resources are greatly appreciated!
4
2168
by: 0to60 | last post by:
I have a question about socket programming in general. Exactly what happens behind the scenes when I one socket connects to a different socket in listen mode? Using the dotnet framework, I create a socket, bind it to a port, put it in listen mode, and then n sockets can connect to it. The code: Socket newSocket = listeningSocket.Accept(); returns a socket. I can communicate on newSocket, and listeningSocket goes
6
7004
by: Laxmikant Rashinkar | last post by:
Is there any way to use a C# socket in promiscuous mode? Any sample code that shows how this is done? any assistance is much appreciated! thanks LK
1
1109
by: Sougato Das | last post by:
Does anyone know any good places for information on sockets programming using VB.NET. I know VB.NET fairly well, but I know very little about sockets. Thanks.
4
6324
by: BadOmen | last post by:
Hi, What is the different between 'System.Net.Sockets.Socket' and 'System.Net.Sockets.TcpClient'? When do I use System.Net.Sockets.TcpClient and System.Net.Sockets.Socket?? Yours, Jonas
3
4364
by: Michael Maercker | last post by:
hi! i'm really not into networking at all and have now been asigned the task of porting a vb6-code into vb.net (compact framework, in this case) and the code uses the winsock-control. i quickly found out that .net uses system.net.sockets.socket or .tcpclient/.tcpserver. and these confuse me... :o| and help would be really great! links, code, wrappers, tips, whateveryougot... one of my main problems, i guess, is: why don't sockets...
2
3317
by: djc | last post by:
I am very new to this... I just started playing around with some network programming. I really only use vb.net. I say that so I don't get the 'use c/c++' answer. Programming is a hobby for me, not a career. I'm only interested, at least right now, in playing around with vb.net and maybe some c#.net. I'm not sure if this is the right forum or not but... my first question is to make sure I understand something: 1) the main difference...
1
1451
by: Farslayer | last post by:
I'm trying to find a good source for programming sockets with VB.NET. The examples in the MSDN help do not show how to accept incoming connections and add this connection to a local array or something similar. Basically, my application will accept a connection, but the client, after the connection is accepted, must authenticate; if it does not, the connection is dropped. But, the sockets are asynchronous and there can be up to 25...
2
6673
by: a_agaga | last post by:
Do you know are there some reasons why many do not make processes to communicate through memory? Why network connections (sockets) are used so commonly in IPC (inter process communication) instead of memory? (Is IPC harder to maintain / handle if it is made through memory, when compared to communication through sockets?) Some background things:
0
9575
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
10564
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
10320
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
10308
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
10073
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
9134
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...
0
6846
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();...
2
3806
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2981
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.