Help with Streams please
BlitzMax Forums/BlitzMax Beginners Area/Help with Streams please
| ||
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! |
| ||
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... |
| ||
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 :( |
| ||
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 |
| ||
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 :) |
| ||
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(). |