473,387 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

[Socket+thread] Send message to all client

Then, I have one client and one server connected trough TCP socket.
When server is listening, client can establish new connection to it.
Every time that new client try to start the connection, the server
use pthread_create() to start a new detached thread for every client.
In this way I can have one server listening and one or more clients
connected. If a client send a particular input, server must disconnect
all clients, close itself and return to prompt.

How can I do that?

With actual scenario only client that have sended that particular
input is disconnected and closed correctly, All other clients that was
connected first are "pending".

Jun 27 '08 #1
16 7210
On 24 Jun 2008 at 17:20, Mariano wrote:
Then, I have one client and one server connected trough TCP socket.
When server is listening, client can establish new connection to it.
Every time that new client try to start the connection, the server
use pthread_create() to start a new detached thread for every client.
In this way I can have one server listening and one or more clients
connected. If a client send a particular input, server must disconnect
all clients, close itself and return to prompt.

How can I do that?
Using exit()?

Jun 27 '08 #2
On 24 Giu, 19:48, Antoninus Twink <nos...@nospam.invalidwrote:
On 24 Jun 2008 at 17:20, Mariano wrote:
Then, I have one client and one server connected trough TCP socket.
When server is listening, client can establish new connection to it.
Every time that new client try to start the connection, *the server
use pthread_create() to start a new detached thread for every client.
In this way I can have one server listening and one or more clients
connected. If a client send a particular input, server must disconnect
all clients, close itself and return to prompt.
How can I do that?

Using exit()?
Sure.
Jun 27 '08 #3
On 24 Giu, 19:56, Mariano <mariano.calan...@gmail.comwrote:
On 24 Giu, 19:48, Antoninus Twink <nos...@nospam.invalidwrote:
On 24 Jun 2008 at 17:20, Mariano wrote:
Then, I have one client and one server connected trough TCP socket.
When server is listening, client can establish new connection to it.
Every time that new client try to start the connection, *the server
use pthread_create() to start a new detached thread for every client.
In this way I can have one server listening and one or more clients
connected. If a client send a particular input, server must disconnect
all clients, close itself and return to prompt.
How can I do that?
Using exit()?

Sure.
but using exit() on server only close the server process and all his
threads, this threads remain pending, I need that after exit all the
clients retuns control to prompt.
Jun 27 '08 #4
Mariano <ma**************@gmail.comwrites:
Then, I have one client and one server connected trough TCP socket.
When server is listening, client can establish new connection to it.
Every time that new client try to start the connection, the server
use pthread_create() to start a new detached thread for every client.
In this way I can have one server listening and one or more clients
connected. If a client send a particular input, server must disconnect
all clients, close itself and return to prompt.

How can I do that?

With actual scenario only client that have sended that particular
input is disconnected and closed correctly, All other clients that was
connected first are "pending".
None of this stuff is supported in standard C. Try asking in a
system-specific newsgroup, perhaps comp.unix.programmer or
comp.programming.threads.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #5
Mariano wrote:
On 24 Giu, 19:56, Mariano <mariano.calan...@gmail.comwrote:
>On 24 Giu, 19:48, Antoninus Twink <nos...@nospam.invalidwrote:
>>On 24 Jun 2008 at 17:20, Mariano wrote:
Then, I have one client and one server connected trough TCP socket.
When server is listening, client can establish new connection to it.
Every time that new client try to start the connection, the server
use pthread_create() to start a new detached thread for every client.
In this way I can have one server listening and one or more clients
connected. If a client send a particular input, server must disconnect
all clients, close itself and return to prompt.
How can I do that?
Using exit()?
Sure.

but using exit() on server only close the server process and all his
threads, this threads remain pending, I need that after exit all the
clients retuns control to prompt.
You can get some functions to execute at normal termination
using atexit.

#include <stdlib.h>

int atexit(void (*func)(void));

I don't know if that is sufficient for your needs.

--
pete
Jun 27 '08 #6
On 24 Jun., 21:20, Mariano <mariano.calan...@gmail.comwrote:
Then, I have one client and one server connected trough TCP socket.
When server is listening, client can establish new connection to it.
Every time that new client try to start the connection, *the server
use pthread_create() to start a new detached thread for every client.
In this way I can have one server listening and one or more clients
connected. If a client send a particular input, server must disconnect
all clients, close itself and return to prompt.

How can I do that?

With actual scenario only client that have sended that particular
input is disconnected and closed correctly, All other clients that was
connected first are "pending".
Make a global var which gets checked by the client thread
if it should close.

but the better way to do things like you want to, is to use
select().
Jun 27 '08 #7
On Jun 24, 10:20*am, Mariano <mariano.calan...@gmail.comwrote:
If a client send a particular input, server must disconnect
all clients, close itself and return to prompt.

How can I do that?
You write the code such that the server detects a particular input and
disconnects all the clients. Doh?
With actual scenario only client that have sended that particular
input is disconnected and closed correctly, All other clients that was
connected first are "pending".
That means you have a bug in your program, doesn't it!

Only a crystal ball could tell me where that bug is, since you haven't
posted even the slightest piece of that program. And that is a good
thing, because that program is severely off-topic here; it belongs in
comp.unix.programmer, or possibly comp.programming.threads.

Jun 27 '08 #8
On 25 Giu, 02:03, pete <pfil...@mindspring.comwrote:
Mariano wrote:
On 24 Giu, 19:56, Mariano <mariano.calan...@gmail.comwrote:
On 24 Giu, 19:48, Antoninus Twink <nos...@nospam.invalidwrote:
>On 24 Jun 2008 at 17:20, Mariano wrote:
Then, I have one client and one server connected trough TCP socket.
When server is listening, client can establish new connection to it.
Every time that new client try to start the connection, the server
use pthread_create() to start a new detached thread for every client.
In this way I can have one server listening and one or more clients
connected. If a client send a particular input, server must disconnect
all clients, close itself and return to prompt.
How can I do that?
Using exit()?
Sure.
but using exit() on server only close the server process and all his
threads, this threads remain pending, I need that after exit all the
clients retuns control to prompt.

You can get some functions to execute at normal termination
using atexit.

#include <stdlib.h>

int atexit(void (*func)(void));

I don't know if that is sufficient for your needs.

--
pete
This function should be used in client. right?
Jun 27 '08 #9
On 25 Jun, 01:44, Nicolas Florian <nicolas...@gmx.dewrote:
On 24 Jun., 21:20, Mariano <mariano.calan...@gmail.comwrote:
Then, I have one client and one server connected trough TCP socket.
When server is listening, client can establish new connection to it.
Every time that new client try to start the connection, *the server
use pthread_create() to start a new detached thread for every client.
In this way I can have one server listening and one or more clients
connected. If a client send a particular input, server must disconnect
all clients, close itself and return to prompt.
How can I do that?
With actual scenario only client that have sended that particular
input is disconnected and closed correctly, All other clients that was
connected first are "pending".

Make a global var which gets checked by the client thread
if it should close.
and if the clients are on a different machine?

but the better way to do things like you want to, is to use
select().
that's what I'd do, but you'd be *much* better off
checking with the experts on Unix and socket programming
on a unix ng.
--
Nick Keighley

Jun 27 '08 #10
Mariano wrote:
On 25 Giu, 02:03, pete <pfil...@mindspring.comwrote:
>Mariano wrote:
>>On 24 Giu, 19:56, Mariano <mariano.calan...@gmail.comwrote:
On 24 Giu, 19:48, Antoninus Twink <nos...@nospam.invalidwrote:
On 24 Jun 2008 at 17:20, Mariano wrote:
>Then, I have one client and one server connected trough TCP socket.
>When server is listening, client can establish new connection to it.
>Every time that new client try to start the connection, the server
>use pthread_create() to start a new detached thread for every client.
>In this way I can have one server listening and one or more clients
>connected. If a client send a particular input, server must disconnect
>all clients, close itself and return to prompt.
>How can I do that?
Using exit()?
Sure.
but using exit() on server only close the server process and all his
threads, this threads remain pending, I need that after exit all the
clients retuns control to prompt.
You can get some functions to execute at normal termination
using atexit.

#include <stdlib.h>

int atexit(void (*func)(void));

I don't know if that is sufficient for your needs.
This function should be used in client. right?
This is not the right newsgroup to find people
who have any idea of which programming issues
are involved with clients and servers.
I don't know anything about clients and servers.

--
pete
Jun 27 '08 #11
On Jun 25, 1:03*pm, Nick Keighley <nick_keighley_nos...@hotmail.com>
wrote:
On 25 Jun, 01:44, Nicolas Florian <nicolas...@gmx.dewrote:
On 24 Jun., 21:20, Mariano <mariano.calan...@gmail.comwrote:
Then, I have one client and one server connected trough TCP socket.
When server is listening, client can establish new connection to it.
Every time that new client try to start the connection, *the server
use pthread_create() to start a new detached thread for every client.
In this way I can have one server listening and one or more clients
connected. If a client send a particular input, server must disconnect
all clients, close itself and return to prompt.
How can I do that?
With actual scenario only client that have sended that particular
input is disconnected and closed correctly, All other clients that was
connected first are "pending".
Make a global var which gets checked by the client thread
if it should close.

and if the clients are on a different machine?
How do you mean?

The autor said, that he wrote a program with more
threads ( one thread per client and one thread which listens for
connections ),
so wheres the problem?
Jun 27 '08 #12
On Jun 25, 1:39 pm, Nicolas Florian <nicolas...@gmx.dewrote:
<snip>
so wheres the problem?
The problem is that this newsgroup is the wrong newsgroup to post
about these things (threads, servers/clients).
Try comp.unix.programmer or comp.programming.threads
Jun 27 '08 #13
On 25 Jun 2008 at 10:39, Nicolas Florian wrote:
On Jun 25, 1:03Â*pm, Nick Keighley <nick_keighley_nos...@hotmail.com>
>and if the clients are on a different machine?

How do you mean?

The autor said, that he wrote a program with more threads ( one thread
per client and one thread which listens for connections ), so wheres
the problem?
It's certainly true that the OP hasn't described his problem very
coherently. However, reading between the lines I think what he may be
asking is how to terminate the processes that are connecting to his
server as clients, not just the threads in the server process dealing
with each client.

That's a slightly odd situation - when the server exits, it will close
all its sockets, and if a client tries to read() from it, the return
value will be less than zero. In that case, the client process can just
exit itself.

We really need more information from the OP - exactly what problem is he
trying to solve, what type of socket is involved, etc.

Jun 27 '08 #14
On Jun 25, 2:57*pm, Antoninus Twink <nos...@nospam.invalidwrote:
On 25 Jun 2008 at 10:39, Nicolas Florian wrote:
On Jun 25, 1:03*pm, Nick Keighley <nick_keighley_nos...@hotmail.com>
and if the clients are on a different machine?
How do you mean?
The autor said, that he wrote a program with more threads ( one thread
per client and one thread which listens for connections ), so wheres
the problem?

It's certainly true that the OP hasn't described his problem very
coherently. However, reading between the lines I think what he may be
asking is how to terminate the processes that are connecting to his
server as clients, not just the threads in the server process dealing
with each client.

That's a slightly odd situation - when the server exits, it will close
all its sockets, and if a client tries to read() from it, the return
value will be less than zero. In that case, the client process can just
exit itself.

We really need more information from the OP - exactly what problem is he
trying to solve, what type of socket is involved, etc.
<OT>
I've been reading comp.lang.c for the past few years. Over time I've
come to recognize the regulars. Some of them are totally brilliant
computer scientists. Some of them are brilliant in all multiple areas
of science. There are two that I think just have a direct line to god.
However ALL them either refer an off topic post to another forum or
they just ignore the poster.

For some strange reason you feel the need to try to be an expert in
off topic posts. You don't seem to understanding that this is a C
forum. Ie, not a place to discuss networking or C++. That is why there
are forums related to those topics. Maybe you are retarded. Who knows.
Either way, I consider you a blemish on this forum.

Now back to our discussion on C.
</OT>
Jun 27 '08 #15
On Jun 25, 2:57*pm, Antoninus Twink <nos...@nospam.invalidwrote:
On 25 Jun 2008 at 10:39, Nicolas Florian wrote:
On Jun 25, 1:03*pm, Nick Keighley <nick_keighley_nos...@hotmail.com>
and if the clients are on a different machine?
How do you mean?
The autor said, that he wrote a program with more threads ( one thread
per client and one thread which listens for connections ), so wheres
the problem?

It's certainly true that the OP hasn't described his problem very
coherently. However, reading between the lines I think what he may be
asking is how to terminate the processes that are connecting to his
server as clients, not just the threads in the server process dealing
with each client.

That's a slightly odd situation - when the server exits, it will close
all its sockets, and if a client tries to read() from it, the return
value will be less than zero. In that case, the client process can just
exit itself.

We really need more information from the OP - exactly what problem is he
trying to solve, what type of socket is involved, etc.
<OT>
I've been reading comp.lang.c for the past few years. Over time I've
come to recognize the regulars. Some of them are totally brilliant
computer scientists. Some of them are brilliant in all multiple areas
of science. There are two that I think just have a direct line to
god.
However ALL them either refer an off topic post to another forum or
they just ignore the poster.

For some strange reason you feel the need to try to be an expert in
off topic posts. You don't seem to understand that this is a C
forum. That is, not a place to discuss networking or C++. That is why
there
are forums related to those topics. Maybe you are retarded. Who
knows.
Either way, I consider you a blemish on this forum.

A while I'm off topic, Google needs to get a few their MIT scientists
to fix the stupid 'remove feature' on this forum.

Now back to our discussion on C.
</OT>

Jun 27 '08 #16
Chad <cd*****@gmail.comwrites:
On Jun 25, 2:57*pm, Antoninus Twink <nos...@nospam.invalidwrote:
[snip]
We really need more information from the OP - exactly what problem is he
trying to solve, what type of socket is involved, etc.

<OT>
I've been reading comp.lang.c for the past few years. Over time I've
come to recognize the regulars. Some of them are totally brilliant
computer scientists. Some of them are brilliant in all multiple areas
of science. There are two that I think just have a direct line to god.
However ALL them either refer an off topic post to another forum or
they just ignore the poster.
[...]
</OT>
"Antoninus Twink" is simply a troll, and is best ignored.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
Jun 27 '08 #17

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

Similar topics

4
by: Wenslauw | last post by:
I have a thread that reads from a socket and I want to put the data that's read into a JTextArea in my gui. What would be the prettiest way of doing this? Listeners? Passing the JTextArea to the...
3
by: Hiroyuki Tanaka | last post by:
Dear Readers, I am trying to learn C# network programming and I have discovered that Windows TCPIP often joins small packets and send them as one to the remote server. This appears to be a...
13
by: Manfred Braun | last post by:
Hi All, I am trying to understand the blocking method socket.Send(). The call blocks as expected, but does this mean, it returnes after the underlying TCP layer got a confirmation, that the send...
1
by: Hasan O | last post by:
hi , I have a problem with socket.send mesajlar = Encoding.ASCII.GetBytes("UGIR"); socketResultValue = socket.Send(mesajlar,0,mesajlar.Length, SocketFlags.None); socketResultValue =...
2
by: Shreddy | last post by:
Hi, I'm trying (or struggling) to convert some C code to C#. The existing C client is sending a structure via a TCP socket to a network server. The structure contains a mix of int and char...
1
by: yaron | last post by:
Hi all, under heavy load i get a SocketException when calling socket.Send method on non blocking socket with error code 10035 WSAEWOULDBLOCK. my question is , how do i know the number of bytes...
1
by: CKane | last post by:
i am trying to build a "missed message" queue on a C# TCP server. many of the devices connecting are mobile and may drop out in bad signal areas. i want to store any messages missed for when they...
2
by: yvan | last post by:
Hi, Here is my client/server scenario: Step1: Client connects to server and sends data sucessfully (using Socket.Send()). Step2: Server gracefully exists (calls Socket.Shutdown() and...
3
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...
3
by: ChristianProgrammer | last post by:
Its been a month and a half now. I have tried to get my WSSF web service to reference a class library that IS a Socket Client. The Socket Client in question runs fine when called by a testing exe....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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
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...

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.