![]() |
|
#1
|
|||
|
|||
Connecting multiple sockets to a serverthis is what i tried for 20 sockets
for(int x = 0; x < 20; x++) { SOCKET sSocket = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); what is the correct way? |
|
#2
|
|||
|
|||
Re: Connecting multiple sockets to a serverQuote:
The correct way to what? If you are thinking about a server that can communicate with 20 clients (each with its own socket/port), then I suggest you visit http://beej.us/guide/bgnet Download the excellent Beej's Guide to Network Programming. A brand-new revision was released a few days ago, but for some years now Beej's Guide has been one of the absolute best jump-starters for beginning to learn sockets programming. There is a multi-client server example, but I suggest that you not try to skip ahead to its section; work your way through the Guide. Read and try to understand and compile (and execute) all of the examples. If you run into problems, then show us what you tried and explain what it is that you don't understand about what did or did not happen when you tried your code. Regards, Dave Last edited by davekw7x : 12-Aug-2007 at 11:40.
|
|
#3
|
|||
|
|||
Re: Connecting multiple sockets to a serverHi Dave, I have read Beej's guide, it's good but I'm learning Winsock...
Yes he does give a multi-connection server example, but my goal is to connect multiple sockets from a single client to a single server and keep them open... that's why I looped the socket, but I'm not sure if that is the correct way since I get errors... maybe it's just minor errors I need to fix or maybe the entire looping concept is impossible? SOCKET sSocket[25]; for(int iCount = 0; iCount < 20; iCount++) { sSocket[iCount] = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); } |
|
#4
|
|||
|
|||
Re: Connecting multiple sockets to a serverQuote:
The whole example in Beej is a little more than 100 lines of "straight" C code. See footnote. Of course you put into the loop whatever it is that you want to do with the sockets that communicate to the 20 client ports. If you want to make a single client program that makes multiple socket connections to a server, you can certainly do it in a loop if you want to. For each connection you have a socket fd and a sock_addr_in structure. If you show us your code and tell us what the errors were (and maybe tell a little about the application), maybe someone can help. Regards, Dave Footnote: I have run a number of Beej's examples (including selectserver.c) on Windows XP with Borland and Microsoft compilers, but my present platform is Linux. If I can't give you specific Windows answers, maybe someone else can. |
|
#5
|
|||
|
|||
Re: Connecting multiple sockets to a serverHi, I think I everything should be fine but there are still errors:
CPP / C++ / C Code:
The errors include: In function 'int main()' 79: a function definition is not allowed here before '{' token 79: expected '.' or ';' before '{' token |
|
#6
|
||||
|
||||
Re: Connecting multiple sockets to a serverQuote:
The last } actually closes main(). I think you want sError() to be outside of your main, not inside. Mark __________________
"Opportunity is missed by most people because it comes dressed in overalls and looks like work." --Thomas Alva Edison "Those who would give up essential liberty to purchase a little temporary safety, deserve neither liberty nor safety." --Benjamin Franklin "A happy person is not a person in a certain set of circumstances, but rather a person with a certain set of attitudes." --Hugh Downs |
|
#7
|
|||
|
|||
Re: Connecting multiple sockets to a serverHi Paul thx for the response, I edited the code too:
CPP / C++ / C Code:
and the result = the error :too many decimal points in number I'm lost on this |
|
#8
|
|||
|
|||
Re: Connecting multiple sockets to a serverQuote:
Note that, regardless of compiler error(s), your code appears to try to make one connection then closes the socket and exits. Huh? The following makes no sense: CPP / C++ / C Code:
Since you said that you wanted 20 sockets open at the same time, wouldn't you need something more like: CPP / C++ / C Code:
Regards, Dave |
|
#9
|
|||
|
|||
Re: Connecting multiple sockets to a serverI got it to work perfect thx for your replies helped so much
|
|
#10
|
|||
|
|||
Re: Connecting multiple sockets to a serverWell, I hope you were able to overcome my obviously incorrect closing loop.
Quote:
That is, I hope that you would have seen that the loop should be more like CPP / C++ / C Code:
I regret the error, but I hope the main idea was clear. Regards, Dave |
Recent GIDBlog
Toyota - 2008 November Promotion by Nihal
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Dediwebhost.com -- Dual Core Server Blowout. Must see to believe | Dediwebhost.com | Managed / Dedicated Servers | 0 | 15-May-2007 12:51 |
| Develop a simple chat application consisting of a client and a server. HELP MEEEEEEE | elcrazy | C++ Forum | 1 | 11-Mar-2007 22:42 |
| Microsoft SQL Server :: SQL Server message 241, state 1, severity 16 | lyuboe | MySQL / PHP Forum | 0 | 11-May-2005 05:31 |
| · Windows 2003 Server Reseller Special: Unlimited Domains/2 GB Space/for $19.99 | contactsonia | Web Hosting Advertisements & Offers | 0 | 09-Jan-2004 06:46 |
| web server in secure mode not connecting to http application | tcsasp | Apache Web Server Forum | 0 | 06-Nov-2003 01:08 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The