Networking

BlitzMax Forums/BlitzMax Beginners Area/Networking

Goober(Posted 2010) [#1]
http://www.blitzmax.com/bmdocs/command.php?name=ReadInt

When this is used on sockets...

Local intPacket:Int = 0

If (ConnectSocket(socket, brl.socket.HostIp("goobs.no-ip.org", 0), 7172)) Then
	stream = CreateSocketStream(socket, True)

	' Possible loop, ect
	If (stream <> Null) Then
		' See if an int has been received
		Try
			Print "Try to read..."
			intPacket = ReadInt(stream)
			Print "DONE"
		Catch ex:Object
			Print "getInt FAIL " + ex.ToString() 
		End Try
	End If
End If


Its blocking! How come? Is their a non-blocking way to read from a socket?


AltanilConard(Posted 2010) [#2]
I don't know if it's possible to setup a non-blocking socket, but you can solve this by checking if there is data available on the stream:

I think that code should work like you want to.


Goober(Posted 2010) [#3]
ReadAvail, where is the documentation for this? How did I miss that!

Thanks Conard! :)


Floyd(Posted 2010) [#4]
ReadAvail, where is the documentation for this?

That's the big challenge with docs. The information is often there, but how do you find it?

Note the integrated help in the IDE has a little more structure than the online docs. For example with sockets the online help for ConnectSocket is an isolated page. But in the IDE if you put the cursor on ConnectSocket and press F1 twice you will see ConnectSocket and many related functions together. Scroll up to the top of the page for an overview.


Goober(Posted 2010) [#5]
There is no IDE documentation on ReadAvail, why not?


Floyd(Posted 2010) [#6]
It's there in the form of a function call SocketReadAvail. You can find it in the list at the top of the BRL.Socket page.

If you click on the source link on that page you will find that SocketReadAvail simply calls a Method named ReadAvail, which is part of the TSocket Type. It is a "convenience" function, mainly for people who are more comfortable with the functional style of older versions of Blitz rather than the native OOP style of BlitzMax:

SocketReadAvail( yourTSocket )
yourTSocket.ReadAvail( )
These accomplish the same thing.

It's rather a lot of work just to discover the ReadAvail method.