Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Callbacks and Timers » Problem with non-blocking mode
Re: Problem with non-blocking mode [message #23505 is a reply to message #23493] Sat, 24 October 2009 18:49 Go to previous messageGo to previous message
mirek is currently offline  mirek
Messages: 14267
Registered: November 2005
Ultimate Member
Weras wrote on Fri, 23 October 2009 05:02

Hi!

I have a problem with sockets, namely, a non-blocking mode. I must say that until that moment I had never worked with sockets and my
question may seem silly.
In my project, I repeated the tutorial from the Help Topics "Connection-Oriented Socket Tutorial"

Function accept_socket.Accept (data_socket, & ip_addr)
suspends the entire program, so I point out that the socket nonblocking:
        Socket::Init();
	
	if( !ServerSocket(accept_socket, portInfo.portNumber) )
		throw Exc("Couldn't bind socket on the local port.");

	if( accept_socket.IsOpen() )
	{
		dword ip_addr;
		accept_socket.Block(false);
                accept_socket.Peek();
		
		if( !accept_socket.IsError() && accept_socket.Accept(data_socket, &ip_addr) )
		{
			Cout() << "Connection from " << FormatIP(ip_addr) << "\n";
			
			while(data_socket.IsOpen() && !data_socket.IsEof() && !data_socket.IsError())
				Cout() << data_socket.Read();
		}
	}


But the program still awaits all perform the function Accept. What I missed or am doing wrong?

Also I read that non-blocking socket's have callback when connection started(or something like that). Could you give examples code using this opportunity socket?

P.S.
Sorry my english )


I belive: Call Peek and only do Accept if it returns true.

Or you can sepcify timeout in Accept (e.g. to zero).

(I belive you in fact do not need non-blocking sockets in that case, but I might be wrong).

Mirek
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: Possible improvements to U++ callbacks
Next Topic: mini BUGFIX in CallbackArgTarget
Goto Forum:
  


Current Time: Tue Aug 26 04:28:47 CEST 2025

Total time taken to generate the page: 0.06185 seconds