View Single Post
Old 06-21-2005, 02:23 AM   #2 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,726
redhead is on a distinguished road
Code:
...
struct connection
{
    ServerSocket ...
Don't you mean
Code:
...
class connection
{
    ServerSocket ...
Code:
...
connection::open();
...
This is not the proper way of doing an open() call to a connection.
Code:
connection connect(3000);
// or
connection connect();
connect->open();
// or 
connect.open();
might be a better aproach, depending on, how you want to dereference your classes.
And in order to have it multithreaded, you need to use some sort of threadding.. One capturing the initial request, which spawns a child process, per clientrequest, doing all the communication with the caller and broadcasting to the clients.
So your codepart
Code:
...
while ( true )
{
    std::string data;
    new_sock >> data;
    spawn_child_broadcast(data);
...
And among others theres alot of syntactical errors, for instance
Code:
...
for(bool iid=0;iid < 100;iid++)
You can't store a value in a bool variabel, it either is true (1, 2, 3, 4, 5 ....) or false (0), it dosn't have a storage facility where you can do calculations on it, for that theres int, double, float, etc.

And why do you do an infinite loop in your open() function, when your main function want's to do one aswell..
Code:
...
ServerSocket server(3000);
...
server.accept (socket[iid]);
...
What does your ServerSocket class look like ??
What book are you learning this from ?
I see alot of loop through alot of sockets, but basicaly, your code isn't much of a multithreaddet solution.
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote