| View previous topic :: View next topic |
| Author |
Message |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Sun Mar 29, 2009 9:44 pm Post subject: 2 clients 1 server (winsock) |
|
|
I'm working on creating a server with multiple clients and I've been presented with two methods to do this. Which one is better?
1. multiple threads
2. ioctlsocket
I have an idea of how to do it, but I'm not entirely sure. Someone shed some light? |
|
| Back to top |
|
 |
oib111 I post too much
Reputation: 0
Joined: 02 Apr 2007 Posts: 2947 Location: you wanna know why?
|
Posted: Sun Mar 29, 2009 10:32 pm Post subject: |
|
|
I would use multiple threads for simplicity. _________________
| 8D wrote: |
cigs dont make people high, which weed does, which causes them to do bad stuff. like killing |
|
|
| Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Sun Mar 29, 2009 11:27 pm Post subject: |
|
|
| How would you use the multiple threads? Would you use a thread to loop accept or would you create a thread for each client (this could lead to problems as state by blankrider if there's a lot of clients)? |
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Sun Mar 29, 2009 11:30 pm Post subject: |
|
|
| OOP |
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
|
| Back to top |
|
 |
Jani Grandmaster Cheater
Reputation: 2
Joined: 29 Dec 2006 Posts: 804
|
Posted: Mon Mar 30, 2009 4:58 am Post subject: |
|
|
| oib111 wrote: | | I would use multiple threads for simplicity. | Just a side note: specially in bigger projects you'll be suffering from lack of performance. I prefer events in every way. |
|
| Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Mon Mar 30, 2009 3:56 pm Post subject: |
|
|
| Can I have code snippet anyone? |
|
| Back to top |
|
 |
sloppy Expert Cheater
Reputation: 0
Joined: 17 Aug 2008 Posts: 123
|
|
| Back to top |
|
 |
slippppppppp Grandmaster Cheater
Reputation: 0
Joined: 08 Aug 2006 Posts: 929
|
Posted: Mon Mar 30, 2009 5:07 pm Post subject: |
|
|
| Look, setup the server like a regular server, but for multi clients this is what you want to do. in the Listen part, you wanna make it keep looping without stopping. Then everytime a client connects, push the socket into a vector, and create a thread to recieve every packet for only that socket. Then if you want to just send a packet to one socket, access the vector, or send the packet to every client by accessing the vector. |
|
| Back to top |
|
 |
Flyte Peanuts!!!!
Reputation: 6
Joined: 19 Apr 2006 Posts: 1887 Location: Canada
|
Posted: Mon Mar 30, 2009 6:17 pm Post subject: |
|
|
| nwongfeiying wrote: | | Can I have code snippet anyone? |
Did you even read my post? Look at it again. Read it very carefully and look at all the links. |
|
| Back to top |
|
 |
nwongfeiying Grandmaster Cheater
Reputation: 2
Joined: 25 Jun 2007 Posts: 695
|
Posted: Mon Mar 30, 2009 7:47 pm Post subject: |
|
|
| Flyte wrote: | | nwongfeiying wrote: | | Can I have code snippet anyone? |
Did you even read my post? Look at it again. Read it very carefully and look at all the links. |
Sorry! I only visited the first link. |
|
| Back to top |
|
 |
Kerelmans Advanced Cheater
Reputation: 0
Joined: 29 Oct 2007 Posts: 57
|
Posted: Tue Mar 31, 2009 10:07 am Post subject: |
|
|
What language? If it's .net then you better use a TcpListener and make a thread for each new client connection. Then store them into a class / list you you can handle them easily.
-Kerelmans |
|
| Back to top |
|
 |
|