Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Multi Client TCP Server

Posted on 2004-04-08
7
Medium Priority
?
337 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

Independent Software Vendors: 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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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