Help with Socket.

I need help with socket.

Page 1 of 1

3 Replies - 778 Views - Last Post: 21 March 2009 - 06:08 PM Rate Topic: -----

#1 almighty  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-March 09

Help with Socket.

Post icon  Posted 20 March 2009 - 04:19 AM

Hey everyone,thank you for reading this post ;).
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.

			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 ;)

Is This A Good Question/Topic? 0
  • +

Replies To: Help with Socket.

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6092
  • View blog
  • Posts: 23,613
  • Joined: 23-August 08

Re: Help with Socket.

Posted 20 March 2009 - 04: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#.
Was This Post Helpful? 0
  • +
  • -

#3 almighty  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 20-March 09

Re: Help with Socket.

Posted 20 March 2009 - 05:21 AM

View PostJackOfAllTrades, on 20 Mar, 2009 - 03:57 AM, said:

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 ;)
and i think that there is a script like that (with multiple clients),
i just can't find it..
Was This Post Helpful? 0
  • +
  • -

#4 Imdsm  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 103
  • View blog
  • Posts: 362
  • Joined: 21-March 09

Re: Help with Socket.

Posted 21 March 2009 - 06:08 PM

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 March 2009 - 06:08 PM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1