Help with Streams please

BlitzMax Forums/BlitzMax Beginners Area/Help with Streams please

Rixarn(Posted 2007) [#1]
First of all, let me introduce myself. I'm a newb in BMax and i want to implement network on a program i have finished. (quite a description huh? but i don't want to bore anyone)

I'm tired :(, i have like 3 days trying to make things work but i get to nowhere... i really need some help.

This is a really stupid question but here it goes. I want to write into a TSocketSTream...

I can use Write(int/byte/string) with file streams like:

local stream:TStream = WriteStream("test.txt")
WriteInt 5

How do i do the same with TSocketStreams?

if i do:

Local ss_stream:TSocketStream = CreateSocketStream(sk_socket)
ss_stream.WriteInt 5

it sais "Error Writing to Stream"

Any Clue?

And btw, i want to do this via sockets even if BnetEx sounds like the best choice... I would use GNet but there arent any working tutorials right now and i cant get it done by myself... :(

Thanks in advance!


rdodson41(Posted 2007) [#2]
Are you sure the sk_socket is open and hasn't been locally or remotely closed?
That's my first guess, as well as maybe a null pointer...


Rixarn(Posted 2007) [#3]
Thanks for yor reply! Well, here is a "complete sample" the later one misses just superstrict and the socket creation...

SuperStrict

Local sk_socket:TSocket = CreateTCPSocket()
Local ss_stream:TSocketStream = CreateSocketStream(sk_socket)

ss_stream.writeInt(5)

Still getting the same error :(


Paposo(Posted 2007) [#4]
Hello

You need connect the socket with remote ip and port.
A socket is like a pipe. It have two points of conection. One is locale and another is remote.

You need use BindSocket() for local point and after ConnectSocket() for remote system.

Bye,
Paposo


Rixarn(Posted 2007) [#5]
Yep, that was the problem, i belived i could write to the TSocketStream w/o being connected to the host... now its working :) , tho i dont get why in the host side if i use StreamSize i get zero but i can read data from it.

Thanks a lot both!

Btw, my english is bad too :)


TomToad(Posted 2007) [#6]
I would think that StreamSize would return -1 since a network connection isn't seekable. If you want to see how many bytes are available to read, then you could use SocketReadAvail().