# Filling in an fd_set array

This topic is 4672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm trying to fill in an fd_set array because I'm trying to learn how to build a simple select() based server for my MMO (I'll change it to IOCP later on). Here's my code:
#include "Global.h"

{
JPlayer p;
fd_set socket_set;

p.id = id;

socket_set.fd_count = id;
socket_set.fd_array = s_arr[64];

return true;
}
}


Doing this gives me this error:
--------------------Configuration: Server - Win32 Debug--------------------
Compiling...
C:\Programs\C++\WinSock\Server\AccountLogIn.cpp(11) : error C2440: '=' : cannot convert from 'unsigned int' to 'unsigned int [64]'
There are no conversions to array types, although there are conversions to references or pointers to arrays
main.cpp
C:\Programs\C++\WinSock\Server\main.cpp(76) : error C2660: 'AccountLogIn' : function does not take 2 parameters
Error executing cl.exe.

Server.exe - 2 error(s), 0 warning(s)


What I'm wondering about is the first error, because I'm positive that the latter one will go away when the first one does. I need a way to pass an array to this function, it seems. How would I do that? Passing it this way, which seems to be the correct one, gives me this error. Passing it as "s_arr[]" gives me yet another error complaining about the function itself and so on. :( Edit: Also, is there a way to pass, for example, all the sockets but the first one (the zero'th element in the s_arr array) to the fd_set array?

##### Share on other sites
You shouldn't manipulate fd_set structures like that. Instead you should use the FD_SET(), FD_CLR(), FD_ISSET() and FD_ZERO() macros.

##### Share on other sites
Thanks!

Any information on how to do this? Parameters etc..

Doesn't seem to be any info on this in MSDN?

##### Share on other sites
Go to http://msdn.microsoft.com. Type FD_SET into the search box and hit go. Lots of info. In particular the second link (the one for select[Winsock]) goes into plenty of detail.

##### Share on other sites
Thanks! Didn't notice it was covered in the select() function!

##### Share on other sites
Ok, I've only really got one question now so I couldn't be bothered to create a new thread for it;

Is there a way to convert from char[] to std::str? I really need to know, because quite frankly I'm fed up with using char[]. Everything works well so far, I just need to know this because WinSocks's recv() function takes a char[] as a parameter for a buffer.

Here's the code so far:

#include "Global.h"bool AccountLogIn(int id, SOCKET s){	JPlayer p;	std::string buf;		p.id = id;		recv(s, (char) buf, sizeof(buf), MSG_PEEK);	if(buf == "ACCOUNTEXISTS")	{		std::cout << "Recieved message!";	}	return true;}

This is the error that I'm getting:

--------------------Configuration: Server - Win32 Debug--------------------Compiling...AccountLogIn.cppC:\Programs\C++\WinSock\Server\AccountLogIn.cpp(10) : error C2440: 'type cast' : cannot convert from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char'        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be calledError executing cl.exe.Server.exe - 1 error(s), 0 warning(s)

bump

##### Share on other sites
First, please post this in the appropriate forum; something like General Programming.

Second, if you read the error message, it explains exactly what the problem is.

##### Share on other sites

This topic is 4672 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

This topic is now closed to further replies.

1. 1
Rutin
32
2. 2
3. 3
4. 4
5. 5

• 13
• 70
• 11
• 10
• 14
• ### Forum Statistics

• Total Topics
632967
• Total Posts
3009571
• ### Who's Online (See full list)

There are no registered users currently online

×