C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 307,175 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,549 people online right now. Registration is fast and FREE... Join Now!




Help with Socket.

 

Help with Socket., I need help with socket.

almighty

20 Mar, 2009 - 03:19 AM
Post #1

New D.I.C Head
*

Joined: 20 Mar, 2009
Posts: 2

Hey everyone,thank you for reading this post wink2.gif.
I am a beginner programmer and i would like to start to work with sockets.
I have read tutorials and more and i can't understand.
I want the server to remain open,i mean also if the client is closing the software,the server works, i tried it and faild,and i want the server not only for one client..for at least 50.
can u give me a start of this?
this is the server code which i faild to do the things i wrote.

CODE

            try
            {
                TcpListener tcpListener = new TcpListener(5555);
                Socket socketForClient = tcpListener.AcceptSocket();
                tcpListener.Start();
                if (socketForClient.Connected)
                {
                    while (true)
                    {
                        Console.WriteLine("Client connected");
                    }
                }
                //socketForClient.Close();
                //Console.WriteLine("Exiting...");
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
            }


thank you very much guys wink2.gif

User is offlineProfile CardPM
+Quote Post

 
Reply to this topicStart new topic
Replies(1 - 3)

JackOfAllTrades

RE: Help With Socket.

20 Mar, 2009 - 03:57 AM
Post #2

I exist to Google your problems.
Group Icon

Joined: 23 Aug, 2008
Posts: 5,324



Thanked: 454 times
Dream Kudos: 50
Expert In: Being annoyed with lazy people.

My Contributions
If you want to handle multiple clients you're going to have to use threads. Here is a nice e-book on Threading in C#.
User is offlineProfile CardPM
+Quote Post

almighty

RE: Help With Socket.

20 Mar, 2009 - 04:21 AM
Post #3

New D.I.C Head
*

Joined: 20 Mar, 2009
Posts: 2

QUOTE(JackOfAllTrades @ 20 Mar, 2009 - 03:57 AM) *

If you want to handle multiple clients you're going to have to use threads. Here is a nice e-book on Threading in C#.


thank you,i'll take a look on it wink2.gif
and i think that there is a script like that (with multiple clients),
i just can't find it..
User is offlineProfile CardPM
+Quote Post

Imdsm

RE: Help With Socket.

21 Mar, 2009 - 05:08 PM
Post #4

New D.I.C Head
Group Icon

Joined: 21 Mar, 2009
Posts: 34



Thanked: 1 times
Dream Kudos: 25
My Contributions
I wrote a HTTP sever a few years ago in C#, using multi-threading and such.

The archive is up at my website, along with the extracted files if you'd prefer to browse!

Hope it helps, it's a bit old!

Archive:
http://imdsm.net/code/imdsmx.zip

Extracted:
http://www.imdsm.net/code/imdsmx/

This post has been edited by Imdsm: 21 Mar, 2009 - 05:08 PM
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:18PM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month