?
Solved

Multi Client TCP Server

Posted on 2004-04-08
7
Medium Priority
?
333 Views
Last Modified: 2010-08-05
Here is the deal:

I need to have a server running that is goign to do two things:

1 - Accept a "registration" or "sign on" from a client application, and store the username and i suppose "socket" of that machine
2 - Accept a "hit" from ANOTHER server application, that is goign to tell the server which "client" (step 1) to notify of a hit

The server app then needs to loop through the list of connected clients, and send the message to each of them.

I am 600% lost.....NOTE: This is not in ANY WAY a commercial application, I am just playing around with C# - trying to learn the ropes.

Any help?

Best,
Avery
0
Comment
Question by:SpecialA10
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
7 Comments
 
LVL 4

Expert Comment

by:caner_elci
ID: 10797310
Okay, your problem is easy.. but will you tell me where do you need help? Or do you want a complete solution for this?
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10797330
One more thing, you can check the following article: http://www.codeproject.com/csharp/tcpclientserver.asp
It's a simple client-server connection using TCP.. And for your second problem, just think that a server can also act as a client to another server. Just connect to other server and send any data you want.
0
 

Author Comment

by:SpecialA10
ID: 10797957
Thanks for your response,

It is not quite as simple as that example (which i have seen before, but thanks for the link). The server probibly needs to be multi-threaded so it can continuesly listen for new connections, thats where the confusion sets in.

Thanks,
Avery
0
 
LVL 4

Expert Comment

by:caner_elci
ID: 10798939
Well, since I don't have a ready sample for you, you better start coding and ask when you're stuck.. I mean, there are a few things you should know. I see that you already know about System.Net, System.Net.Sockets and simple socket programming. You'll just have to create a listener using TcpListener, start listening.. and when a client connects to your listener, you will Accept() it and pass this Socket object to a new thread. That's it.. Your thread will take care of the client. And also you can do some messaging between threads and your main thread (using delegates, events).
I suggest you to create a listener thread, so your server will always be listening.
So, your server application will be something like this:

ClientThread ct;
Thread t;
TcpListener listener = new TcpListener( IPAddress.Any, 5678 );
while( true )
{
    listener.Start();
    Socket s = listener.AcceptSocket();
    ct = new ClientThread( s, this );
    t = new Thread( new ThreadStart( ct.Run ) );
}

public class ClientThread
{
    Socket s = null;
    Object parent = null;

    public ClientThread( Socket _s, Object _parent )
    {
        s = _s;
        parent = _parent;
    }

    public void Run()
    {
        // Do your client work here... possibly an infinite loop with read operation,
        // processing them etc...
    }
}

The above code is just written here.. I didn't test it, there might be many errors/warnings.. just look as a pseudo-code..

Caner
0
 
LVL 4

Accepted Solution

by:
caner_elci earned 2000 total points
ID: 10798982
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question