winsock

Why can a socket connect() to its own ephemeral port?

对着背影说爱祢 提交于 2020-02-03 05:07:26
问题 I can reliably get a Winsock socket to connect() to itself if I connect to localhost with a port in the range of automatically assigned ephemeral ports (5000–65534). Specifically, Windows appears to have a system-wide rolling port number which is the next port that it will try to assign as a local port number for a client socket. If I create sockets until the assigned number is just below my target port number, and then repeatedly create a socket and attempt to connect to that port number, I

Why can a socket connect() to its own ephemeral port?

為{幸葍}努か 提交于 2020-02-03 05:07:24
问题 I can reliably get a Winsock socket to connect() to itself if I connect to localhost with a port in the range of automatically assigned ephemeral ports (5000–65534). Specifically, Windows appears to have a system-wide rolling port number which is the next port that it will try to assign as a local port number for a client socket. If I create sockets until the assigned number is just below my target port number, and then repeatedly create a socket and attempt to connect to that port number, I

How to use SO_KEEPALIVE with TServerSocket?

故事扮演 提交于 2020-01-25 07:43:26
问题 Does the component has a set option property or i need to use setsockopt function ? i want to enable the os built in Keep-alive instead of me having to write it myself... -.-" so, my question is, inside the constructor where i create the instance of TServerSocket, how do i then enable this SO_KEEPALIVE option ? thanks everyone. 回答1: You can use setsockopt to set SO_KEEPALIVE implementation uses WinSock; {$R *.dfm} procedure TForm2.ClientConnect(Sender: TObject; Socket: TCustomWinSocket); var

C winsock “rolling parsing”

…衆ロ難τιáo~ 提交于 2020-01-25 03:21:09
问题 i'm trying to receive data from a server and parse it. http://pastebin.com/1kjXnXwq http://pastebin.com/XpGSgRBh everything works as is, but i want to parse the data instead of just grabbing blocks of it and printing it out. so is there any way to grab data from the winsock until \n then stop and pass it off to another function to be parsed and once that function returns continue reading from the last point until another \n shows up and repeate the process until there is nothing left to

(GET HTTP Request) C++ sockets using winsock.h

限于喜欢 提交于 2020-01-25 03:03:18
问题 Okay, before anyone jumps to conclusions (and do to the fact of me keeping this relevant to others), basically, I'm trying to make a Get Request with sockets in C/C++ using Winsock.h. [ Main problem existing in running of the SocketRequest Function ] I've been getting error response codes anywhere from: "WSAENOTCONN 10057" to "WSAENOTSOCK 10038" which, I found more information on that here: https://msdn.microsoft.com/en-us/library/windows/desktop/ms740668(v=vs.85).aspx Now, this is going to

Getting the IP of the interface that received a recvfrom() UDP packet (Microsoft)

偶尔善良 提交于 2020-01-17 01:19:07
问题 Using recvfrom() on a socket bound to INADDR_ANY on a Microsoft multihomed PC. when recvfrom() gets an UDP packet: how can I find the Interface (IP) that received the packet? 回答1: There is no way to know the receiving IP when a single listening socket is bound to multiple IPs. Instead of binding a single socket to INADDR_ANY , you can query the machine's list of local IPs using GetAdaptersInfo() and/or GetAdapterAddresses() , then create a separate listening socket for each IP. You can use

Migrating C++CLI wrapper from .NET 4.0 to 4.5 cause winsock error on Windows Server 2012 R2

喜你入骨 提交于 2020-01-15 23:55:47
问题 I have build a C++ CLI wrapper for a communication middleware we use. The wrapper has been in .NET 4.5 and works fine in Windows 7 and Windows Server 2008 R2. But in Windows Server 2012 R2 it crashes with an "Access violation" error in mswsock.dll The interesting part is that if I build the wrapper and test application to target .NET 4.0 it works. But when I re-target them to .NET 4.5.x it triggers the exception. I've tried to investigate security, strong naming, hot-fix'ing .NET, but to no

Fill data into the recv-Buffer locally

有些话、适合烂在心里 提交于 2020-01-14 10:42:36
问题 I hook into the send and recv functions in Windows. In some situations I modify the data that's going to be sent and read. In the send function, this is easy. I hook into the function, modify the source buffer and then pass it to the original function. But for the recv function, this is more complicated. When I've called the original recv function and I'm going to decide to add more data, I need to push data into the local queue so that the next call of recv would return those bytes. Any

sockaddr_in6 not declared?

拟墨画扇 提交于 2020-01-13 14:56:54
问题 I'm trying to port an ipv4 server/client to ipv6, but the compiler says SOCKADDR_IN6 is not declared in the scope. SOCKADDR_IN is declared but not SOCKADDR_IN6 . <Winsock2.h> is included. Any one have any ideas why it would be undeclared? 回答1: Microsoft's documentation for sockaddr_in6 says that it is defined in the ws2tcpip.h header, probably you need to include that. On Linux you'd need different includes, sys/socket.h and netinet/in.h . 回答2: I have currently found SOCKADDR_IN6 definition

Implement a good performing “to-send” queue with TCP

好久不见. 提交于 2020-01-13 07:14:32
问题 In order not to flood the remote endpoint my server app will have to implement a "to-send" queue of packets I wish to send. I use Windows Winsock, I/O Completion Ports. So, I know that when my code calls "socket->send(.....)" my custom "send()" function will check to see if a data is already "on the wire" (towards that socket). If a data is indeed on the wire it will simply queue the data to be sent later. If no data is on the wire it will call WSASend() to really send the data. So far