Receiving telnet stream

BlitzMax Forums/BlitzMax Programming/Receiving telnet stream

maverick69(Posted 2009) [#1]
Hello!

I'm really new to networking and currently experimenting a little bit.

What I'm currently try to achieve is to listen to a local port and receive data that I'm sending using telnet.

I'm using the following BlitzMax source:
Graphics 640,480

Local socket:TSocket = CreateTCPSocket()
Local stream:TSocketStream = CreateSocketStream(socket)
If BindSocket(socket, 9090)
	SocketListen(socket)
	While (Not KeyDown(KEY_ESCAPE))
		Cls
		
		DrawText "Listening...", 10, 10
		If SocketReadAvail(socket) > 0
			DrawText "Receiving", 30, 10
			Print "Receiving...."
			Local data:String = ReadString(stream, SocketReadAvail(socket))			Print data
		End If
		
		Flip
	Wend
Else
	Print "fail"
End If


On the shell I open a connection using:
telnet localhost 9090


But when I'm typing and sending data, the BlitzMax client seems to never receive anything.

Greetz... Joe


maverick69(Posted 2009) [#2]
Hey,

I've found the problem. I'd had to create a listening socket using SocketAccept() and then use SocketReadAvail on this socket.

Now everything works fine.


kRUZe(Posted 2011) [#3]
Any chance of a repost of the fixed code bud?


Corum(Posted 2011) [#4]
@kRUZe: try this. ;)



Last edited 2011


kRUZe(Posted 2011) [#5]
Thanks Corum ;) Networking with standard Blitz was simple but it was just the Binding and Listening I wasn't sure with BMax.