winsock

WSAEWOULDBLOCK handling

放肆的年华 提交于 2020-08-27 21:25:39
问题 I have written a socket for a server in C++ CLI that is using winsock. The sockets are using async methods for sending, receiving and accepting connections. After implementing my socket in the production environment, the send function stops working giving me the error WSAEWOULDBLOCK. Out from my research on the net, this means the network buffer for socket IO is full or the networking is too busy to do my operation at this moment. However, I have not seen any specific solution which can

Can't create socket on Windows

只谈情不闲聊 提交于 2020-08-22 05:05:25
问题 I have quite an embarrassing problem. The following code simply will not create a socket on Windows; it fails and displays the error message. Could anyone briefly explain why this might be? I'm incredibly confused and frustrated that something so simple is failing. Thank you. int sock; if( (sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { printf("error opening socket"); } EDIT: Also, printing out strerror(errno) simply shows "No error". 回答1: You need to call WSAStartup() before any other

Can't create socket on Windows

99封情书 提交于 2020-08-22 05:05:06
问题 I have quite an embarrassing problem. The following code simply will not create a socket on Windows; it fails and displays the error message. Could anyone briefly explain why this might be? I'm incredibly confused and frustrated that something so simple is failing. Thank you. int sock; if( (sock = socket(AF_INET, SOCK_STREAM, 0)) < 0 ) { printf("error opening socket"); } EDIT: Also, printing out strerror(errno) simply shows "No error". 回答1: You need to call WSAStartup() before any other

Howto set the UDP source address on Windows

末鹿安然 提交于 2020-08-08 12:04:41
问题 There seems to be no portable way to set the source IP for sending UDP datagrams from sockets bound to INADDR_ANY, but at least on Linux and FreeBSD it can be done using sendmsg() and the IP_PKTINFO (Linux) or IP_SENDSRCADDR (FreeBSD) option. (See this question.) Is there an equivalent option to set the UDP source IP on Windows ? 回答1: From MSDN: WSASendMsg function [...] On an IPv4 socket of type SOCK_DGRAM or SOCK_RAW , an application can specific the local IP source address to use for

C++ header files for UDP in Windows?

旧巷老猫 提交于 2020-06-24 12:34:09
问题 I have a linux applications which sends data over UDP protocol. It uses these header files: #include <stdio.h> /* standard C i/o facilities */ #include <stdlib.h> /* needed for atoi() */ #include <unistd.h> /* defines STDIN_FILENO, system calls,etc */ #include <sys/types.h> /* system data type definitions */ #include <sys/socket.h> /* socket specific definitions */ #include <netinet/in.h> /* INET constants and stuff */ #include <arpa/inet.h> /* IP address conversion stuff */ #include <netdb.h

Netinet and netdb not found, c++ network libraries

南笙酒味 提交于 2020-06-17 09:57:07
问题 I was trying to run example codes to learn how to use winsock on c++ from the following links: http://www.linuxhowtos.org/data/6/client.c http://www.linuxhowtos.org/data/6/server.c and the following libraries: #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> was not at the default mingw libraries, and by trying to google it wasn't much of a success because it end up requiring other libraries to run. if anyone have a link to the full library or it with the dependencies, i

how to link winsock in cmake?

放肆的年华 提交于 2020-05-25 11:27:24
问题 I found only this strings find_library(WSOCK32_LIBRARY wsock32) find_library(WS2_32_LIBRARY ws2_32) (i'm begginer in cmake) how to link winsock2 (winsock?) in cmake? 回答1: Since these are both part of the Windows SDK, you shouldn't need to do a search for them. Assuming you have the SDK installed, you can just do something like: add_executable(MyExe main.cpp) if(WIN32) target_link_libraries(MyExe wsock32 ws2_32) endif() 来源: https://stackoverflow.com/questions/15119639/how-to-link-winsock-in

Windows Socket编程简介

喜欢而已 提交于 2020-04-03 22:16:03
WinSock编程 使用WinSock API的编程,应该了解TCP/IP的基础知识。虽然你可以直接使用WinSock API来写网络应用程序,但是,要写出优秀的网络应用程序,还是必须对TCP/IP协议有一些了解的。 1. TCP/IP协议与WinSock网络编程接口的关系 WinSock并不是一种网络协议,它只是一个网络编程接口,也就是说,它不是协议,但是它可以访问很多种网络协议,你可以把他当作一些协议的封装。现在的WinSock已经基本上实现了与协议无关。你可以使用WinSock来调用多种协议的功能。那么,WinSock和TCP/IP协议到底是什么关系呢?实际上,WinSock就是TCP/IP协议的一种封装,你可以通过调用WinSock的接口函数来调用TCP/IP的各种功能.例如我想用TCP/IP协议发送数据,你就可以使用WinSock的接口函数Send()来调用TCP/IP的发送数据功能,至于具体怎么发送数据,WinSock已经帮你封装好了这种功能。 2、TCP/IP协议介绍 TCP/IP协议包含的范围非常的广,他是一种四层协议,包含了各种硬件、软件需求的定义。 TCP/IP协议确切的说法应该是TCP/UDP/IP协议。UDP协议(User Datagram Protocol 用户数据报协议),是一种保护消息边界的,不保障可靠数据的传输。TCP协议(Transmission