winsock2

Winsock2 - How to use IOCP on client side

匆匆过客 提交于 2019-11-29 10:56:07
问题 I’ve recently started learning IOCP on Windows and been reading the following article: http://www.codeproject.com/Tips/95363/Another-TCP-echo-server-using-IOCP You can download the sample for the article from: http://dl.dropbox.com/u/281215/documentation/iocp-1.00.html The sample contains two simple applications – iocp_echo_server and TcpEchoClient . I understand that IOCP is usually used on the server side of the client/server model but I’d like to create a client using IOCP. I’ve so far

TCP Hole Punching

若如初见. 提交于 2019-11-28 16:54:22
I'm trying to implement TCP hole punching with windows socket using mingw toolchain. I think the process is right but the hole doesn't seems to take. I used this as reference. A and B connect to the server S S sends to A , B 's router IP + the port it used to connect to S S does the same for B A start 2 threads: One thread tries connecting to B 's router with the info sent by S The other thread is waiting for an incoming connection on the same port used to connect to its router when it connected to S B does the same I have no issue in the code I think since: A and B does get each other ip and

Winsock2's select() on fd 0 (stdin) fails

99封情书 提交于 2019-11-28 12:27:31
问题 Using Winsock2 the code sequence below returns -1 (failure) for select() . #include <Winsock2.h> #include <stdio.h> ... int rc; int fdstdin = fileno(stdin); /* returns 0 as expected */ fd_set fds; FD_ZERO(&fds); FD_SET(fdstdin, &fds); rc = select(1, &fds, NULL, NULL, NULL); ... Is this the expected behaviour when using Winsock2 or am I missing something? 回答1: This is expected behavior. As mentioned all over the documentation, winsock's select function only works on sockets, and stdin is not a

TCP Winsock: accept multiple connections/clients

夙愿已清 提交于 2019-11-28 00:31:41
I tried to can multiply clients, and send it to each one. But it working only for one, after one client connected the server just useless for incoming connections. while(true) { if(Sub = accept(Socket, (sockaddr*)&IncomingAddress, &AddressLen)) { for(int i = 0; i < MaxUsers; i++) { if(!ClientAddress[i].sin_family) { ClientAddress[i] = IncomingAddress; char Version[128], Dir[256], Path[256], URL[128], Message[256]; GetCurrentDirectory(256, Dir); sprintf(Path, "%s\\Version.ini", Dir); GetPrivateProfileString("Default", "Version", "1.0.0.0", Version, 128, Path); GetPrivateProfileString("Default",

API using sockaddr_storage

时间秒杀一切 提交于 2019-11-27 12:30:44
问题 I'm trying to do some IP agnostic coding and as suggested by various sources I tried to use sockaddr_storage. However all the API calls (getaddrinfo, getnameinfo) still depend on struct sockaddr. And casting between them isn't exactly a good option, gves rise to a lot of other problems. And casting to sockaddr_in and sockaddr_in6 separately sort of defeats the purpose of me trying to use sockaddr_storage. Anybody who has effectively used sockaddr_storage in devloping a simple client server

TCP Hole Punching

蹲街弑〆低调 提交于 2019-11-27 10:02:07
问题 I'm trying to implement TCP hole punching with windows socket using mingw toolchain. I think the process is right but the hole doesn't seems to take. I used this as reference. A and B connect to the server S S sends to A , B 's router IP + the port it used to connect to S S does the same for B A start 2 threads: One thread tries connecting to B 's router with the info sent by S The other thread is waiting for an incoming connection on the same port used to connect to its router when it

Serialization of struct

好久不见. 提交于 2019-11-27 08:27:58
Suppose i have a struct whose member values i want to send over the network to another system using winsock 2. I'm using C++ language. How do i convert it to char * keeping in mind that the struct has to be serialized before sending and also how do i deserialize the char * into struct at the other end? I found boost serialization as a suggestion to similar question but can anyone illustrate with a small code snippet for both serialization and deserialization ? This question might seem very basic but the other answers to the related posts did not help much. Following example shows a simplest

TCP Winsock: accept multiple connections/clients

泪湿孤枕 提交于 2019-11-26 23:27:11
问题 I tried to can multiply clients, and send it to each one. But it working only for one, after one client connected the server just useless for incoming connections. while(true) { if(Sub = accept(Socket, (sockaddr*)&IncomingAddress, &AddressLen)) { for(int i = 0; i < MaxUsers; i++) { if(!ClientAddress[i].sin_family) { ClientAddress[i] = IncomingAddress; char Version[128], Dir[256], Path[256], URL[128], Message[256]; GetCurrentDirectory(256, Dir); sprintf(Path, "%s\\Version.ini", Dir);

Cannot include both files (WinSock2, Windows.h)

孤街浪徒 提交于 2019-11-26 21:14:57
问题 I'm having a problem including both files. Now, I know I need to either include Winsock2 first, then windows.h, or simply put: #define WIN32_LEAN_AND_MEAN but, I'm still having problems I have a header file that is called XS.h which looks like this #ifndef XS_H #define XS_H #include <winsock2.h> #include <ws2tcpip.h> #include <Windows.h> #endif and I'm including XS.h in the header Client.h . Client.h include is looks like this : #ifndef CLIENT_H #define CLIENT_H #include "XS.h" XS.h is my

Serialization of struct

牧云@^-^@ 提交于 2019-11-26 12:45:08
问题 Suppose i have a struct whose member values i want to send over the network to another system using winsock 2. I\'m using C++ language. How do i convert it to char * keeping in mind that the struct has to be serialized before sending and also how do i deserialize the char * into struct at the other end? I found boost serialization as a suggestion to similar question but can anyone illustrate with a small code snippet for both serialization and deserialization ? This question might seem very