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). 11 2213
Bonj <a@b.com> scribbled the following
on comp.lang.c: 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.
Neither C or C++ has any socket, TCP, or other networking support
whatsoever. The fact that you are cross-posting to
microsoft.publi c.vc.language looks like you are using Microsoft
Windows. I advise therefore to ask on
comp.os.ms-windows.program mer.win32.
If, by any chance, you are using Unix, ask on comp.unix.progr ammer.
--
/-- Joona Palaste (pa*****@cc.hel sinki.fi) ------------- Finland --------\
\-------------------------------------------------------- rules! --------/
"This is a personnel commuter."
- Train driver in Scientific American
Yes.. You can have a server that listens at a desired port for
multiple-clients and communicates using that same port. If you are using
blocking socket, you will have to spawn a worker thread to handle each
client connection.
You probably want to take a look at the following article about blocking and
non-blocking socket : http://www.developerfusion.co.uk/show/28/8/
TanKC
"Bonj" <a@b.com> wrote in message news:34******** *****@individua l.net... 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).
Ta very much, appreciate it
"TanKC" <kc*****@google .com> wrote in message
news:O7******** ********@TK2MSF TNGP15.phx.gbl. .. Yes.. You can have a server that listens at a desired port for multiple-clients and communicates using that same port. If you are using blocking socket, you will have to spawn a worker thread to handle each client connection.
You probably want to take a look at the following article about blocking and non-blocking socket :
http://www.developerfusion.co.uk/show/28/8/
TanKC
"Bonj" <a@b.com> wrote in message news:34******** *****@individua l.net... 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).
Off topic for comp.lang.*
However, I suggest you look at some C++ libraries for this sort of thing.
e.g. CommonC++ or ACE.
e.g. http://www.gnu.org/software/commoncp...p-example.html
I wrote that a while back and I would do it very differently today.
Bonj wrote: 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).
Bonj wrote: 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 as well as windows, (the only thing seemingly different in linux seems to be that it has different includes and doesn't have to call WSAStartup).
You are way off topic for c.l.c, and probably for c.l.c++ also,
both of which deal only with the portable ISO standardized
languages (which are not the same). The standard languages do not
contain sockets, multithreading, etc. You should read a newsgroup
for a while before posting into it. You should also set followups
to one group when initially posting a cross-posted inquiry.
--
"If you want to post a followup via groups.google.c om, don't use
the broken "Reply" link at the bottom of the article. Click on
"show options" at the top of the article, then click on the
"Reply" at the bottom of the article headers." - Keith Thompson
Bonj wrote: 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:
Yes, more than one way exists to do what you're describing. You could
call listen() and fork on each accept(), or you could use the select()
system call. Forking on accept() generates overhead on process
creation/switching and is generally more cumbersome than using
select(). select() blocks and waits for input/output from user defined
file descriptors. When input/output arrives on one of these file
descriptors, select() returns the file descriptor in question, allowing
for efficient "multiplexi ng" of requests using only a single process.
As always, see select()'s man pages for more information.
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),...
Yes, call the setsockopt() function with the SO_REUSEADDR parameter
set.
setsockopt(SOCK , SOL_SOCKET, SO_REUSEADDR,1)
-dave Yes, more than one way exists to do what you're describing. You could call listen() and fork on each accept(), or you could use the select() system call. Forking on accept() generates overhead on process creation/switching and is generally more cumbersome than using select().
Honestly in modern UNIX systems fork()ing doesn't have that much
overhead. It used to be that the entire process space had to be copied
to the new process, but now the page tables are simply marked
copy-on-write, and no actual copying of pages takes place except when
changes occur.
Jon
----
Learn to program using Linux assembly language http://www.cafeshops.com/bartlettpublish.8640017
"Bonj" <a@b.com> дÈëÓʼþ news:34******** *****@individua l.net... 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).
There are several ways to do that without multithreading.
You can use select in linux and WaitForMultiple Objects in windows.
"Bonj" <a@b.com> дÈëÓʼþ news:34******** *****@individua l.net... 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).
There are several ways to do that without multithreading.
You can use select in linux and WaitForMultiple Objects in windows. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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!
|
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
|
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
|
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.
|
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
| |
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...
|
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...
|
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...
|
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:
|
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 usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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,...
| |
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,...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
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...
| |