-
I get an error msg - Failed to set socket option "TCP_NODELAY" ; all your TCP packets will be buffered
What's wrong?
-
You probably don't have permission to set the TCP_NODELAY option on your socket, which is done automatically by SFML. This can be either because this is how the administrator configured it, your socket number is lower than 1024 in which case you shouldn't be able to create the socket in the first place, or although highly improbable the operating system doesn't support TCP_NODELAY.
Show us some code and we can figure out what might have caused it. However bear in mind, the cause is not something SFML has any influence on, so it will be up to you to fix the problem.
-
You probably don't have permission to set the TCP_NODELAY option on your socket, which is done automatically by SFML. This can be either because this is how the administrator configured it, your socket number is lower than 1024 in which case you shouldn't be able to create the socket in the first place, or although highly improbable the operating system doesn't support TCP_NODELAY.
Show us some code and we can figure out what might have caused it. However bear in mind, the cause is not something SFML has any influence on, so it will be up to you to fix the problem.
The code is the exact program on the github page. It runs fine at my home, but not at my school :(
So I'm guessing my school administrator configured it this way... Is there a workaround? :(
-
The code is the exact program on the github page.
You really need to be more specific than this. What program? There are multiple, and each takes their own parameters. We aren't psychic...
It runs fine at my home, but not at my school :(
Did you even read what I posted? Unless you are bringing the same physical computer (laptop) to school and accessing the school network from your laptop running the same operating system, things will be different because the computers are configured differently. SFML doesn't automatically give you administrator privileges. I wouldn't be surprised if this was security related. Like I said, go to the administrator and ask them why you can't set TCP_NODELAY on sockets. This might not even be an SFML problem. If you are still convinced SFML can change this, at least provide information about the school computer. What operating system does it run? What version of that operating system? Can the other examples run fine? Can other network programs run fine? How did you run the program?
Like I said, we are not psychic. We need more information besides "it doesn't work on my school network". We don't even know what exactly this it even is.
-
The code is the exact program on the github page.
You really need to be more specific than this. What program? There are multiple, and each takes their own parameters. We aren't psychic...
It runs fine at my home, but not at my school :(
Did you even read what I posted? Unless you are bringing the same physical computer (laptop) to school and accessing the school network from your laptop running the same operating system, things will be different because the computers are configured differently. SFML doesn't automatically give you administrator privileges. I wouldn't be surprised if this was security related. Like I said, go to the administrator and ask them why you can't set TCP_NODELAY on sockets. This might not even be an SFML problem. If you are still convinced SFML can change this, at least provide information about the school computer. What operating system does it run? What version of that operating system? Can the other examples run fine? Can other network programs run fine? How did you run the program?
Like I said, we are not psychic. We need more information besides "it doesn't work on my school network". We don't even know what exactly this it even is.
I'm sorry if I didn't make this clear. I was referring to this example code on github page https://github.com/SFML/SFML/tree/master/examples/sockets
Ok, now i understand that this has got to do with school computers, not the school internet.
Since this doesn't seem to be a SFML problem like you said, is there any workaround other than telling my school administrator to reconfigure the school computers so that SFML has permission to set TCP_NODELAY (They won't do it)
-
What other output is produced when you run the program?
How did you run it? As a server/client or both?
Does the program function as expected even when the error gets shown on the console or does it not do anything?
You can also try adding
std::cout << WSAGetLastError() << std::endl;
to the end of the main() function right before it returns and show us the error number that gets printed.
-
(http://i.imgur.com/3k2LUFY.png)
-
Since everything fails, and you get error 10038 (WSAENOTSOCK: "socket operation on nonsocket"), it seems like the sockets are not even created for some reason. I should definitely add a check to make the error clearer.
However I have no idea why you wouldn't be able to create any socket. But I'm sure binary1248 has some hints ;)
-
Paste the following code into a new project, build it, run it, and paste the output of the program here.
#pragma comment( lib, "Ws2_32.lib" )
#include <iostream>
#include <windows.h>
int main() {
int error = 0;
WSADATA data;
error = WSAStartup( MAKEWORD( 2, 2 ), &data );
if( error ) {
std::cout << "WSAStartup() failed: " << error << "\n";
return -1;
}
SOCKET s = socket( PF_INET, SOCK_STREAM, 0 );
if( s == INVALID_SOCKET ) {
std::cout << "socket() failed: " << WSAGetLastError() << "\n";
return -1;
}
u_long block = 1;
error = ioctlsocket( s, FIONBIO, &block );
if( error == SOCKET_ERROR ) {
std::cout << "ioctlsocket() failed: " << WSAGetLastError() << "\n";
return -1;
}
int no_delay = 1;
error = setsockopt( s, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast<char*>( &no_delay ), sizeof( no_delay ) );
if( error == SOCKET_ERROR ) {
std::cout << "setsockopt() failed: " << WSAGetLastError() << "\n";
return -1;
}
error = closesocket( s );
if( error == SOCKET_ERROR ) {
std::cout << "closesocket() failed: " << WSAGetLastError() << "\n";
return -1;
}
error = WSACleanup();
if( error == SOCKET_ERROR ) {
std::cout << "WSACleanup() failed: " << WSAGetLastError() << "\n";
return -1;
}
std::cout << "Everything completed successfully.\n";
return 0;
}
-
socket() failed: 10022
-
MSDN says
WSAEINVAL (10022): Invalid argument
I have no idea why... maybe a permission problem?
-
Only thing I could find on google that might help is this (http://us.generation-nt.com/answer/socket-returns-error-10022-help-30461162.html).
Use 0 instead of IPPROTO_TCP
PPROTO_TCP (defined as 6 in winsock2.h) has never worked for me.
This totally contradicts the Microsoft docs, but it was the only way for me
to get it work (on XP!).
So what happens if you try that solution?
-
Seriously... do people not read what has already been posted? I think it is clear that the call to socket() fails and the test program never gets to setsockopt()? So your advice makes no sense.
-
I will admit I didn't read the entire code, but think about it. Maybe if one define is causing issues in one call, maybe another define is causing other issues. After all that is what the error is, "WSAEINVAL (10022): Invalid argument".
I'm also curious to know if the school computers in question happen to be running Windows XP ;)
-
A quick search gave a few hints: it might be a permission issue (try to run the app with admin privileges, or from another drive) or the antivirus somehow interfering (try to disable it).
-
try to run the app with admin privileges
iride already mentioned how presumably uncooperative the administrators are. So this is not really an option. Also, I don't know how Microsoft handles permission errors or "access denied" errors, but from MSDN documentation it seems the only close match, WSAEACCES, is only returned when trying to access already created sockets, so I can only assume this really is a permission problem.
iride, what output does this code produce?
#pragma comment( lib, "Ws2_32.lib" )
#include <iostream>
#include <winsock2.h>
int main() {
int error = 0;
WSADATA data;
error = WSAStartup( MAKEWORD( 2, 2 ), &data );
if( error ) {
std::cout << "WSAStartup() failed: " << error << "\n";
return -1;
}
SOCKET s = WSASocket( AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0 );
if( s == INVALID_SOCKET ) {
std::cout << "IPv4 socket() failed: " << WSAGetLastError() << "\n";
s = WSASocket( AF_INET6, SOCK_STREAM, IPPROTO_TCP, NULL, 0, 0 );
if( s == INVALID_SOCKET ) {
std::cout << "IPv6 socket() failed: " << WSAGetLastError() << "\n";
return -1;
}
}
error = closesocket( s );
if( error == SOCKET_ERROR ) {
std::cout << "closesocket() failed: " << WSAGetLastError() << "\n";
return -1;
}
error = WSACleanup();
if( error == SOCKET_ERROR ) {
std::cout << "WSACleanup() failed: " << WSAGetLastError() << "\n";
return -1;
}
std::cout << "Everything completed successfully.\n";
return 0;
}
-
IPv4 socket() failed: 10022
IPv6 socket() failed: 10022
-
This is probably a permission problem... can you use any other network program that isn't installed on the local machine? Or do they also fail to connect?
-
This is probably a permission problem... can you use any other network program that isn't installed on the local machine? Or do they also fail to connect?
I downloaded Google Chrome and it works fine.
-
I downloaded Google Chrome and it works fine.
Just so there is no ambiguity, you downloaded Google Chrome, installed it, and ran it and it can load web pages properly? I looked at the Chrome source code and they use the same functions as in the code snippets I already posted.
Can you try to download something "smaller" and that doesn't require an install. Something that can run by itself right from the .exe at the location you downloaded it to. I attached a test program I had lying around so you can see if it downloads the HTTP source of the website it tries to connect to.
You could also try going for broke and installing Code::Blocks and testing from there. If the headers that came with Visual Studio are really screwed up then there is nothing else you can do with it.
-
Do you actually know which kind of antivirus/firewall is running on the PCs? I remember the Comodo Firewall causing rather weird API behavior, even while being deactivated (like crashing QT programs just because they tried to create a socket).
Also wouldn't consider Chrome being some reliable test, because most firewalls will most likely let it pass based on their own whitelists.
-
Do you actually know which kind of antivirus/firewall is running on the PCs? I remember the Comodo Firewall causing rather weird API behavior, even while being deactivated (like crashing QT programs just because they tried to create a socket).
Also wouldn't consider Chrome being some reliable test, because most firewalls will most likely let it pass based on their own whitelists.
McAfee
This is probably a permission problem... can you use any other network program that isn't installed on the local machine? Or do they also fail to connect?
I downloaded Google Chrome and it works fine.
I can't confirm if your program is working because it closes to fast before I can see the output. I can't even run the program from command prompt because it's disabled. Howerver, I tried running an old chat program that I made with SFML 2.0 and strangely, it works.
-
I can't even run the program from command prompt because it's disabled.
Sounds like a fun time... My program should have spit out a fairly long HTML document on the console, so if it closes that fast, it probably means it failed somewhere. Try to run it from the "Run" menu in Windows (Windows key + R) and output the output to some file with:
HelloWorld.exe > output.txt
Maybe that will work.
Howerver, I tried running an old chat program that I made with SFML 2.0 and strangely, it works.
Try other settings and IDEs. Maybe static linking works, maybe Code::Blocks/MinGW works. We really shouldn't try understand how Microsoft implemented it's winsock API/security/DLLs and just trial and error until we find something that works.
-
wait... I got it to work now.
If the exectuable is located in a clouded drive, it doesn't work...
But if the executable is in a computer's local drive(C: for example), everything suddenly works!
Appreciate the help anyways. Thanks :)