winsock2

Flush a socket in C++

本秂侑毒 提交于 2019-12-08 08:30:33
I tried to flush a socket after calling to send function in c++. I used winsock2.h library. I need to send the data immediatly after the send message, but I can not find any function like flash function. I am trying to send messages to a device and it expect receiving messages one by one. I mean that if I sending two messages in the sender like "MessageOne" and "MessageTwo", the receiver received "MessageOneMessageTwo" that is not seperate, and the device not recognize the commands. So how can I do that? There is nothing you can do on the send side to make the receive side receive messages

Flush a socket in C++

孤街浪徒 提交于 2019-12-08 04:32:09
问题 I tried to flush a socket after calling to send function in c++. I used winsock2.h library. I need to send the data immediatly after the send message, but I can not find any function like flash function. I am trying to send messages to a device and it expect receiving messages one by one. I mean that if I sending two messages in the sender like "MessageOne" and "MessageTwo", the receiver received "MessageOneMessageTwo" that is not seperate, and the device not recognize the commands. So how

Redirect IO of process to Windows socket

删除回忆录丶 提交于 2019-12-07 09:48:23
问题 I am new to winsock, I tried to write a server socket that accepts new connection, then it calls an external executable file. How can we redirect the stdin and stdout of the external executable file to the client socket which has been accepted. I googled and found the code below but it does not work. The new process was created successfully but the client could not receive any data from the new process. I am using Windows 7 and Visual Studio 2008 Express edition. Any helps and comments are

Listening to a UDP broadcast

房东的猫 提交于 2019-12-06 16:53:11
I need to listen to a network broadcast coming over UDP. The datagram contains a j4cDAC_broadcast struct. I have tried following a few tutorials, but they seem to have left a few things out and dont have very detailed explanations, if any. With what I have right now I am getting an error BIND FAILED 10049 and error 10049 indicates that the address is unavailable. The broadcast is coming in on 255.255.255.255:7654. How do I fix this error? This is what I have so far: void test() { WSADATA wsd; SOCKET s; j4cDAC_broadcast recieve; char *read = (char*) malloc(sizeof(j4cDAC_broadcast)); int ret;

Delphi TClientSocket replacement using winsock2 and IOCP?

。_饼干妹妹 提交于 2019-12-06 06:58:06
Is there such a thing? It needs to be asynchronous (no Indy). Try HPScktSrvr - http://www.torry.net/pages.php?id=220#939383 These may or may not be what you are looking for, but worth a shot: Ararat Synapse - For Delphi 2009 support you need to get the latest from SVN. /n Software's IP*Works - Commercial, but very full featured. Good luck! Check http://voipobjects.com/index.php?page=delphi-iocp-library It is migrated iocpclasses.sourceforge.net (i'm an author). Enjoy :) 来源: https://stackoverflow.com/questions/1072510/delphi-tclientsocket-replacement-using-winsock2-and-iocp

Make c++ not wait for user input

大憨熊 提交于 2019-12-06 05:08:59
So, i am trying to make a c++ WinSock2 chatter, just for learning. It is a console application and i want to take user input (for sending to the counterpart), but i still want to be able to recive. (so you can write a message while still being able to recive one)... When using cin >> input; the program "pauses" until the user has enterd something, that way it is "turn based" (one user writes something and sends it, then the other user writes something and sends it). Is there a way to make the user be able to write something WHILE the recive stuff is still running? (Preferably something else

Redirect IO of process to Windows socket

被刻印的时光 ゝ 提交于 2019-12-05 16:14:48
I am new to winsock, I tried to write a server socket that accepts new connection, then it calls an external executable file. How can we redirect the stdin and stdout of the external executable file to the client socket which has been accepted. I googled and found the code below but it does not work. The new process was created successfully but the client could not receive any data from the new process. I am using Windows 7 and Visual Studio 2008 Express edition. Any helps and comments are appreciated. Thank a lot! the server #include <winsock2.h> #include <ws2tcpip.h> #include <stdio.h>

Get formatted message for WSA error codes

百般思念 提交于 2019-12-05 04:23:39
问题 i'm using winsock2 in a win32 c++ application. I would display with MessageBox the network errors that i can retrieve by calling WSAGetLastError(). How can i do this? I saw FormatMessage but i didn't understand how to use it 回答1: Here's how for example, The following searches error code in the system's message table and places the formatted message in LPTSTR Error buffer. // Create a reliable, stream socket using TCP. if ((sockClient = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { DWORD

Are close() and closesocket() interchangable?

南笙酒味 提交于 2019-12-05 04:08:22
I've seen a lot of answers here that say to use close() to destroy a socket but the guide I used from msdn has me using closesocket(). I'm wondering if there is a difference and if there are reasons to use one or the other. In both cases, I am seeing the suggestion to use shutdown() so that's all well and good. SergeyA close() is a *nix function. It will work on any file descriptor, and sockets in *nix are an example of a file descriptor, so it would correctly close sockets as well. closesocket() is a Windows-specific function, which works specifically with sockets. Sockets on Windows do not

how to use WSAConnect and WSAAccept for sending receving init Data before accept a request

僤鯓⒐⒋嵵緔 提交于 2019-12-04 23:16:44
As title, I 've searched in msdn or on internet for an example but I didn't find any one >_< All case they use WSAConnect ( S, sa, sa_len , NULL ,NULL ,NULL ,NULL ); I wanna use those function (WSAConnect & WSAAccept) for a simple authority with key in lpCallerData->buf before accept I 've tried the example about WSAAccept from msdn for server side and my simple code about WSAConnect but It's alway "lpCallerData == NULL" Sorry about my bad english Thank you in advance with any help! My not working code: Server side: SOCKET SV_Socket; struct sockaddr_in SV_Channel; WORD SV_wVersionRequested;