By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,266 Members | 1,816 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,266 IT Pros & Developers. It's quick & easy.

Socket connection c++.net Help me please

P: n/a
Please help me, I have to make socket connection between server and
more than one client on some port. Is it possibly? I make socket
between server and one client, but more then one is problem. I know
that I have to put connected clients in some arraylist but how to
accept them, and how to communicate ith them. Sorry on my English.

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
1. open a socket with some port on the server:

SOCKET sServerSocket;

SOCKADDR_IN sServerIn;

memset(&sServerIn,0,sizeof(sServerIn));

sServerIn.sin_family=AF_INET;

sServerIn.sin_port=htons(hPortNumber);

sServerIn.sin_addr.s_addr=htonl(INADDR_ANY);

//open server-side socket

sServerIn=socket(AF_INET,SOCK_STREAM,0);

bind(sServerSocket,(LPSOCKADDR)&sServerIn,sizeof(s ServerIn))

2. declare an array of client sockets, and loop through the array, for each
client socket:

SOCKET sClientSocket[nCount];

SOCKADDR sClientSocketAddress[nCount]

for (int i=0; i<nCount; i++)

{

sClientSocket[i]=accept(sServerSocket, &sClientSocketAddress[i],
&nLength);

};

3. Now you should be able to connect to multiple clients.

J.W.

"Alisa" <al***********@hotmail-dot-com.no-spam.invalid> wrote in message
news:40**********@127.0.0.1...
Please help me, I have to make socket connection between server and
more than one client on some port. Is it possibly? I make socket
between server and one client, but more then one is problem. I know
that I have to put connected clients in some arraylist but how to
accept them, and how to communicate ith them. Sorry on my English.

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups ---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption

=---
Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.