winsock2

ws2_32.lib vs. libws2_32.a, what's the difference and how to link libws2_32 to NB project?

主宰稳场 提交于 2019-12-04 19:28:16
I use NetBeans, Windows and Cygwin with g++ compiler. I'm examining Windows Sockets 2. I do everything that is written in MS manual . I have a code (mostly from this manual): #include <winsock2.h> #include <ws2tcpip.h> #include <cstdlib> #include <iostream> #pragma comment(lib, "Ws2_32.lib") int main() { WSADATA wsaData; int iResult; // Initialize Winsock iResult = WSAStartup(MAKEWORD(2,2), &wsaData); if (iResult != 0) { printf("WSAStartup failed: %d\n", iResult); return 1; } else cout << "Initialization OK."; return 0; } And I have a problem when I try to run the project: undefined reference

Determine between socket and fd

烂漫一生 提交于 2019-12-04 16:33:07
问题 On unix everything is a file approach of function read() , write() , close() is not supported on Win32. I want to emulate it but have no idea how to distinguish when sock is socket or fd on WinSocks2. //returns 1 if `sock` is network socket, // 0 if `sock` is file desriptor (including stdio, stderr, stdout), ... // -1 in none of above int is_net_socket(int sock) { // ...? } This should work as in : int mysock = socket(PF_INET, SOCK_STREAM, 0); int myfd = _open("my_file.txt", _O_RDONLY);

C++ Socket recv mixed messages

China☆狼群 提交于 2019-12-04 06:34:19
问题 Hello i am having a problem with a socket server and client. The problem is that the messages get mixed up when i send them really fast. When i send them lets say 1 message per second everything runs good, but when i sned them 1 message per 40ms they get mixed up. here is my code for recieving: std::string* AteneaClient::readSocket () { std::string finalString = std::string(""); int size = MSG_SIZE; bool receiving = true; int timesBufferInc=0; while (receiving) { std::string temporalString; /

How to use inet_pton() with the mingw compiler?

狂风中的少年 提交于 2019-12-03 09:47:33
问题 I'm trying to add IPv6 compatibility to an already IPv4-compatible program in C, but having some problems with the compiler. Currently compiling with mingw32-gcc-4.6.2, which gives me a linking error when using the function inet_pton. I've tried making it compile for vista(as inet_pton is a vista function), but it seems like the whole function is missing from mingw. Is there any way to add it to mingw, or any other options I may have missed? 回答1: Looking in my past codes - Tested in MinGW/GCC

WINSOCK - Setting a timeout for a connection attempt on a non existing IP?

自作多情 提交于 2019-12-03 01:50:31
I am developing a RTSP Source filter in C++, and I am using WINSOCK 2.0 - blocking socket. When I create a blocking socket, I set its SO_RCVTIMEO to 3 secs like so: int ReceiveTimeout = 3000; int e = setsockopt(Socket, SOL_SOCKET, SO_RCVTIMEO, (char*)&ReceiveTimeout, sizeof(int)); My filter tries to connect to IP_ADDRESS:554 (554 is RTSP server port). If there is a server listening on that IP on the port 554, all goes well, but: If my filter creates a socket to an existing IP address , but on a random port which no one listens on, connect() waits for 3 secs and returns WSAETIMEDOUT . So after

How to use inet_pton() with the mingw compiler?

谁说胖子不能爱 提交于 2019-12-03 01:25:17
I'm trying to add IPv6 compatibility to an already IPv4-compatible program in C, but having some problems with the compiler. Currently compiling with mingw32-gcc-4.6.2, which gives me a linking error when using the function inet_pton. I've tried making it compile for vista(as inet_pton is a vista function), but it seems like the whole function is missing from mingw. Is there any way to add it to mingw, or any other options I may have missed? Looking in my past codes - Tested in MinGW/GCC: int inet_pton(int af, const char *src, char *dst) { switch (af) { case AF_INET: return inet_pton4(src, dst

C++ Socket recv mixed messages

爷,独闯天下 提交于 2019-12-02 08:11:12
Hello i am having a problem with a socket server and client. The problem is that the messages get mixed up when i send them really fast. When i send them lets say 1 message per second everything runs good, but when i sned them 1 message per 40ms they get mixed up. here is my code for recieving: std::string* AteneaClient::readSocket () { std::string finalString = std::string(""); int size = MSG_SIZE; bool receiving = true; int timesBufferInc=0; while (receiving) { std::string temporalString; //create an empty buffer char* RCV_BUFFER = (char*) malloc (size* sizeof(char)); for(int i=0;i<size;i++)

Why does the following code make my computer beep?

ぃ、小莉子 提交于 2019-12-02 07:11:09
I'm having a really hard time understanding why is this piece of code making my computer beep. I've isolated this section of code to be the one producing the occasional beep, but I don't see what's the problem with it. const int BUFFER_LENGTH = 8192; char buffer [BUFFER_LENGTH + 1]; int recvResult; do { recvResult = recv(webSocket, buffer, BUFFER_LENGTH, 0); buffer[recvResult] = '\0'; printf("%s", buffer); if (recvResult > 0) { sendResult = send(clientSocket, buffer, recvResult, 0); } }while (recvResult > 0); shutdown(webSocket, SD_SEND); To give a little bit of context, this is for a computer

WSA error 10048 when binding server sockets

痞子三分冷 提交于 2019-12-02 03:06:40
问题 I started with the simple server tutorial on the msdn website in order to learn how to use sockets in client and server applications. Once I was done following thet tutorial, I started adapting the client and server code into multithreaded proggrams in order to make a tchat client and server. Everything was going very well until I ran into WSA error 10048. I tried using different ports for each socket but it still did not solve the error. Here is my server code : #undef UNICODE #define WIN32

Problem using Connect(), send(), recv, with UDP sockets

时光怂恿深爱的人放手 提交于 2019-12-01 06:42:46
For my Uni assignment I have to create a fast action paced networked game and so have chosen to use UDP as opposed to TCP. I am aware of a lot of the differences in programming both UDP and TCP and have read through most of the relevant parts of MSDN's documentation on winsock. On MSDN it states that creating a UDP socket via the connect() function should bind the socket to the address and port specified and as a result be able use the send() and recv() functions with the created socket. For my application I create a client and use connect() using the loopback address which sends a number of