FAQ Database Discussion Community


Winsock asynchronous multiple WSASend with one single buffer

asynchronous,buffer,winsock,send,iocp
MSDN states "For a Winsock application, once the WSASend function is called, the system owns these buffers and the application may not access them." In a server application, does that mean that if I want to broadcast a message to multiple clients I cannot use a single buffer that holds...

Should WSASocket() be used with IOCP?

c++,sockets,winsock,iocp,overlapped-io
I know that it is recommended to use WSAAccept() instead of accept() when creating an IOCP application. But I am not sure if WSASocket() belongs to the Overlapped I/O functions, or is it just another Winsock function?

gethostbyname and endianness - how are the bytes returned?

winapi,language-agnostic,winsock,endianness
On my (Intel) x86 machine, I've noticed that if I printf the results of gethostbyname for localhost, I get 100007F, even though the MSDN documentation states it should return the IP in network byte order, aka big endian. I searched a bit and found this topic. Based on the answers...

“Un-associate” socket from completion port

c++,sockets,winapi,winsock,iocp
CreateIoCompletionPort() is used to associate a socket with a completion port. However, when this socket is closed, then I need to "un-associate" it from the completion port. How can I do that?

UTF8 Byte to String & Winsock GetStream

c#,utf-8,winsock,utf8-decode
Well, I'm trying to convert a large information in bytes for string. (11076 length) The problem in the end, the information is with missing characters. (length 10996) Look: The information is received by Winsock connection, look the proccess: public static void UpdateClient(UserConnection client) { string data = null; Decoder utf8Decoder...

How do applications handle ports if they are not open?

c++,sockets,winsock
I am trying to write an application in c++ using winsock. I need to handle a case where default port used by the app is not open to use then what is fallback mechanism?

Netcat like listening program in delphi does not send back commands

sockets,delphi,winsock,remote-access,netcat
I have a delphi program that listens to port 8080 using winsock here is the code so far: program Project1; {$APPTYPE CONSOLE} uses Windows, SysUtils, WinSock; var WSAData: TWSAData; ServerSocket,ClientSocket: TSocket; ServerAddr, ClientAddr: TSockAddr; ClientAddrSize,Status,ret: Integer; Buffer1,buffer2: array[0..1024] of Char; begin writeln('started..'); WSAStartup($0101,WSAData); ServerSocket:=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); ServerAddr.sin_family:=AF_INET; ServerAddr.sin_port:=htons(8080); ServerAddr.sin_addr.S_addr:=INADDR_ANY;...

C++ sockets: communication between PCs over internet

c++,network-programming,winsock
I'm writing a program on Windows using winsocks that can send messages to another computer. The client connects with the server in the other computer and begin exchanging data. It works fine on my local network using local addresses(192.168.1.*), but I can't communicate with public addresses (216.185.45.129); not even my...

Delphi winsock why does sockaddr_in values get “garbled” when assigning InAddr.S_addr

delphi,winsock
I found a function to test if a specific tcp port is open on a remote PC. It appears to work alright, but when I assign a value to the variable client.sin_addr.S_addr the other values appear to be assigned with garbled values, well at least I didn't expect to see...

Winsock invalid received byte number

c++,c++11,winsock
I'm currently facing a Winsock related problem when trying to validate the number of received bytes. In my application I'm using a non-blocking socket in order to throw my own Timeout exception. Here the according code for the initialization of Winsock: // Initialize Winsock WSAData winSockData; WORD dllVersion = MAKEWORD(2,...

Get IP address for all connections in Delphi

delphi,winsock
The following code returns the IP address of the first TCP/IP connection for a machine. uses WinSock; // ... function GetLocalIP() : String; var addr: TSockAddrIn; phe: PHostEnt; szHostName: array[0..128] of Char; socketData: TWSADATA; begin Result := '127.0.0.1'; // Initialize the socket API if (WSAStartup($101, socketData) = 0) then begin...

String Length Winsock + UTF8 + “ç”

c#,ruby,utf-8,winsock
Actually I have a problem with "receive data" in server. Everything works fine , here's what the server does with the data it receives: string data = null; byte[] buffer = new byte[40000]; client.TCPClient.GetStream().Read(buffer, 0, 40000); data = Encoding.UTF8.GetString(buffer); Server.Network.ReceiveData.SelectPacket(client.Index, data); Void: public static void SelectPacket(int Index, string data) {...

How to prevent empty input on a WinSock in C

c,winsock
I have a WinSock client script in C that, when i just press enter without any input, hangs up. sry i cant tell you more, i tried to read the buffer after the input but not even this is working. Thats my code: printf("\ninput [max 256]: "); gets(buf); send(s,buf,strlen(buf),0); rc=recv(s,buf,256,0);...

Retrieving port number using winsock sockets API

c,sockets,winsock
Although I do get a non-zero value for port number from the code segment below, the value returned for port does not match the value for port used to establish the socket: #include <winsock2.h> int main(void) { SOCKADDR_IN server; WSADATA wsa; SOCKET s; DWORD dwTime = 1000; if (WSAStartup(MAKEWORD(2,2),&wsa) !=...

How to extract data from HTTP header in C?

c,http-headers,winsock
Today I am asking how to extract the data section from the received buffer in my recv() in C (not C++). I just need some suggestions, how would I get HTTP/1.1 200 OK\r\n Date: Mon, 23 May 2005 22:38:34 GMT\r\n Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)\r\n Last-Modified: Wed, 08 Jan 2003 23:11:55...

Does WSASend() hide batching of large buffers?

tcp,buffer,winsock
I'm testing large buffers right now and I am setting it in WSABUF and calling WSASend() next. Thing though, is that WSARecv() just handed it back that large buffer in one go. Does that make sense? Where is the limit of WSASend() and WSARecv() with with respect to large buffers?...

How to exit a blocking recv() call?

c++,sockets,winapi,network-programming,winsock
Based on this question, when you call closesocket() on a socket that recv() is already using, then an RST packet will be sent to the other side instead of performing a graceful disconnection (4-way handshake). But I wish to perform a graceful disconnection, so I need to exit recv() before...

recv function always gives me the same buffer

c++,sockets,winsock,winsock2
This question is kind of a follow-up of a question that I previously asked. Basically I had a c++ server running in ubuntu and I'm now trying to make this code works in windows. I am having some issues with windows socket as it's my first time using them. After...

Winsock binding on the same port

c++,windows,winsock
So I recently decided to dabble into winsock and network programming a bit by using a guide I found and searching the net, but I have run into a problem which I am not really sure how i should solve. I'm trying to make a very simple chat system, I've...

IOCP notification without completion key

c,winsock,winsock2,iocp
I am building an IOCP/RIO Winsock server and have been struggling with getting the proper notification from the completion port when my AcceptEx() calls are triggered by a client request. When I call GetQueuedCompletionStatus() after having sent a client request, I will get a successful return but without the completion...

Is it unsafe to send and receive raw structures through sockets?

c++,winsock
I'm working on a remoting control program. I need to send and receive multiple data at once. I use this solution: struct PACKET { int x; int y; }; //... PACKET p; p.x = 10; p.y = 5; send(socket, (char*)&p, sizeof(PACKET), 0); However, I'm considering if this is a safe...

Is legacy winsock available for windows store apps? [closed]

c#,windows-store-apps,winsock
I know that code on windows store which used socket needed to use the StreamSocket class instead of the legacy winsock API (Socket class) And it is clearly something that prevent me from migrating my open source library whose lots of app would depends. Now, I've seen that VS 2013...

What IO operations causes completion packets to be sent to the completion port when using sockets?

c++,sockets,winsock,iocp
In IOCP, when starting an IO operation such as WSARecv(), a completion packet will be sent to the completion port when the IO operation completes. What I want to know is what IO operations causes completion packets to be sent to the completion port when using sockets, for example, I...

Why do inet_ntoa and inet_ntop “reverse” the bytes?

c,networking,winsock,byte-order
This is a rather basic problem with which, to my surprise, I've had a problem today. It looks to me like inet_pton and inet_ntoa are reversing the bytes of the IP address they're given: DWORD IP; inet_pton(AF_INET, "192.168.0.1", &IP); printf("%08X\n", IP); This will print 0100A8C0. And well, if we break...

Should I use different WSAOVERLAPPED struct for WSASend and WSARecv?

windows,sockets,winsock,winsock2
I'm developing a server-client application using WinSock. Does using the same WSAOVERLAPPED with both WSASend and WSARecv works well? Should I use different WSAOVERLAPPED struct for WSASend and WSARecv?...

Pinvoke / call native Windows API function from C#

c#,dll,winsock,winsock2,winsockets
from within my C#-application I use functions of an external DLL. This DLL itself uses network functions. So it is necessary to initialise Winsock out of my C#-application to let the network sockets work for this DLL. That's how I try to execute WSAStartup for initialisation, but it does not...

Get all IP-Addresses in C

c,winsock
I have the following problem. I have to write a Plugin for Pidgin in the Language C. I am completely new to C. I found the following Code. WORD wVersionRequested; WSADATA wsaData; char name[255]; char* ip; PHOSTENT hostinfo; wVersionRequested = MAKEWORD( 2, 0 ); if ( WSAStartup( wVersionRequested, &wsaData )...

WSASend completion routine has never been called

c++,windows,winsock,winsock2,overlapped-io
I'm playing around with Overlapped IO and suddenly found out that it looks like I'm the only one who can't encourage Completion callback to work (All claims was about: it works and I don't like it). The idea of my application is: a client (telnet localhost 27015) connects to the...

Physical disconnection from network and intermittent socket error 10057

sockets,winsock
A customer of mine has a Windows application where there is a network connection between two machines. The system is supposed to cope with the connection being lost. It does this by keeping a counter on the client position which is reset every time data is received from the server....

Passing member function which takes another member function and var to a std::thread

multithreading,c++11,winsock
I've searched for solutions, but after trying about 10 approaches I cannot solve my compilation issue: functional(1149): error C2064: term does not evaluate to a function taking 2 arguments Here's the part of my code. pConnectedClients.push_back(new RemoteClient(hClientSocket, RemoteClientNumber)); if (pConnectedClients.size() > 1) { for (int unsigned i = 0; i...