Solved

Multi Client TCP Server

Posted on 2004-04-08
7
331 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 500 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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

749 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