-
X-Received: by 10.31.41.81 with SMTP id p78mr382813vkp.2.1512514005035; Tue, 05 Dec
2017 14:46:45 -0800 (PST)
X-Received: by 10.31.41.81 with SMTP id p78mr382813vkp.2.1512514005035; Tue, 05 Dec
2017 14:46:45 -0800 (PST)
Path: news-archive.icm.edu.pl!news.icm.edu.pl!news.nask.pl!news.nask.org.pl!news.unit
0.net!peer03.am4!peer.am4.highwinds-media.com!peer03.iad!feed-me.highwinds-medi
a.com!news.highwinds-media.com!m31no429089qtf.0!news-out.google.com!t48ni949qtc
.1!nntp.google.com!g35no428797qtk.1!postnews.google.com!glegroupsg2000goo.googl
egroups.com!not-for-mail
Newsgroups: pl.comp.programming
Date: Tue, 5 Dec 2017 14:46:44 -0800 (PST)
In-Reply-To: <6...@g...com>
Complaints-To: g...@g...com
Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=37.47.48.37;
posting-account=Sb6m8goAAABbWsBL7gouk3bfLsuxwMgN
NNTP-Posting-Host: 37.47.48.37
References: <6...@g...com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <4...@g...com>
Subject: Re: from blocking to nonblocking server
From: fir <p...@g...com>
Injection-Date: Tue, 05 Dec 2017 22:46:45 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 5744
X-Received-Body-CRC: 2600097416
Xref: news-archive.icm.edu.pl pl.comp.programming:211841
[ ukryj nagłówki ]W dniu wtorek, 5 grudnia 2017 17:32:33 UTC+1 użytkownik fir napisał:
> his is offtopic but maybe someone here will/would know
>
> i dont like to read a weeks on tcp and sockets as this is a lot and confusing
> (i prefer this time to spend on c/graphics etc)
>
> i got some old tcp-server (on winapi winsock2) code, that worked but it was
> not tested/inspected for being ok and was yet only working in blocking mode
>
> the code goes
>
> int SetupBlockingWinsockServer()
> {
>
> WSADATA wsaData;
> WSAStartup(MAKEWORD(2,2), &wsaData);
>
> /// Creating socket
>
> servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
>
> SOCKADDR_IN sin;
> sin.sin_family = PF_INET;
> sin.sin_port = htons(1111);
> sin.sin_addr.s_addr = INADDR_ANY;
>
> //bind
>
> int retVal = bind(servSock, (LPSOCKADDR)&sin, sizeof(sin));
>
> /// Trying to listen socket
>
> retVal = listen(servSock, 10);
>
> // Waiting for a client
>
> ServClientSock = accept(servSock, NULL, NULL); return
1;
>
>
> }
>
> (i skipped the few lines of retvalue checking for errors for clarity)
>
> my goal is just to turn it to non blocking without a lot of work but i would like
to know this is ok
>
> i checked experimentally via message boxes that it "blocks" on accept call
> (block may be euphemism a bit here as it hang real hard, when no client is run then
not only hourglass-pointer is shown, not only app gets fully unresponsible and non
redraws itself but even closing it form task manager is hard, its possible but takes
few seconds to kill)
>
> what i did :
>
> i added some line thet is supposed to set socked as nonblocked and move accept to
separate function which i call then periodically (from run frame event)
>
> int SetupBlockingWinsockServer()
> {
>
> WSADATA wsaData;
> WSAStartup(MAKEWORD(2,2), &wsaData);
>
> /// Creating socket
>
> servSock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
>
> SOCKADDR_IN sin;
> sin.sin_family = PF_INET;
> sin.sin_port = htons(1111);
> sin.sin_addr.s_addr = INADDR_ANY;
>
> //bind
>
> int retVal = bind(servSock, (LPSOCKADDR)&sin, sizeof(sin));
>
> /// Trying to listen socket
>
> retVal = listen(servSock, 10);
>
> // set no blocking
>
> u_long no_block=1;
> ioctlsocket(servSock,FIONBIO,&no_block);
>
> }
>
> int WaitForClientAccept()
> {
> /// Waiting for a client
>
> ServClientSock = accept(servSock, NULL, NULL);
>
> if(ServClientSock == INVALID_SOCKET) return 0;
>
>
> u_long no_block=1;
> ioctlsocket(ServClientSock,FIONBIO,&no_block);
> return 1;
>
> }
>
> this last one is as i said run periodically on server app frame and when it return
1 (it means it gett accepted connection?) i flag out both server code to not call it
more and
> client not to send more connections
>
> it seem to work but as this is my
> own slight experimentation only i would like to get pproval/confirmation
> that this is in fact ok
>
> is this ok or is there something wrong with it?
>
> (btw as a side questions, do i need those flaging out here, or if i connected i
could not bother for flaging out more sendings for connections and checks for
incomming connections? (i know it would be wastefull maybe to send it still 50 times
a second after connection was accepted but besides this waste would it work? (if that
would be work maybe sending it once a second would work as
> automatic connection reboval when something would get disconnected?)
>
> tnx for answer if someone know whats goin on in that sockets/winsock, i got not
much time for that
>
> (fir)
moge dodac ze to chyba dziala ok
- za to przelaczenie connecta w
kliencie na nie-blokujacy chyba nie da sie tak prosto zrobic a nie
moge nigdzie w google znalezc gotowego kodu jak to zrobic
(a czytac o tym kilka/nascie/dziesiat godzin nie mam jakos checi bo to straszne
smieci)
Następne wpisy z tego wątku
- 08.12.17 09:30 Roman Tyczka
- 08.12.17 17:58 fir
- 08.12.17 18:13 fir
Najnowsze wątki z tej grupy
- Can you activate BMW 48V 10Ah Li-Ion battery, connecting to CAN-USB laptop interface ?
- We Wrocławiu ruszyła Odra 5, pierwszy w Polsce komputer kwantowy z nadprzewodzącymi kubitami
- Ada-Europe - AEiC 2025 early registration deadline imminent
- John Carmack twierdzi, że gdyby gry były optymalizowane, to wystarczyły by stare kompy
- Ada-Europe Int.Conf. Reliable Software Technologies, AEiC 2025
- Linuks od wer. 6.15 przestanie wspierać procesory 486 i będzie wymagać min. Pentium
- ,,Polski przemysł jest w stanie agonalnym" - podkreślił dobitnie, wskazując na brak zamówień.
- Rewolucja w debugowaniu!!! SI analizuje zrzuty pamięci systemu M$ Windows!!!
- Brednie w wiki - hasło Dehomag
- Perfidne ataki krakerów z KRLD na skrypciarzy JS i Pajton
- Instytut IDEAS może zacząć działać: "Ma to być unikalny w europejskiej skali ośrodek badań nad sztuczną inteligencją."
- Instytut IDEAS może zacząć działać: "Ma to być unikalny w europejskiej skali ośrodek badań nad sztuczną inteligencją."
- Instytut IDEAS może zacząć działać: "Ma to być unikalny w europejskiej skali ośrodek badań nad sztuczną inteligencją."
- U nas propagują modę na SI, a w Chinach naukowcy SI po kolei umierają w wieku 40-50lat
- C++. Podróż Po Języku - komentarz
Najnowsze wątki
- 2025-07-12 Warszawa => PC Hardware Expert / Specjalista PC <=
- 2025-07-12 Warszawa => Account Manager - Usługi rekrutacyjne <=
- 2025-07-12 Warszawa => Administrator IT <=
- 2025-07-12 Warszawa => IT Administrator <=
- 2025-07-12 Warszawa => Asystent/tka ds. Administracji <=
- 2025-07-12 Warszawa => Specjalista/stka ds. Organizacji <=
- 2025-07-12 Warszawa => MENA New Business Manager <=
- 2025-07-12 Gdynia => Controlling systems Consultant <=
- 2025-07-12 Warszawa => Developer Microsoft Dynamics 365 Finance & Operations (D36
- 2025-07-12 Warszawa => Programista Microsoft Dynamics 365 Finance & Operations (D
- 2025-07-12 Warszawa => Dyrektor IT <=
- 2025-07-12 Warszawa => IT Director <=
- 2025-07-12 Czy wypowiedź Kaczyńskiego o Braunie jest skarżalna? ["działa z OBCEJ inspiracji"]
- 2025-07-11 Rejestrator temperatur - termopara, siec
- 2025-07-11 DPD, przeniesienie numerów z a2mobile i z Orange