UDP Send and Recieve

BlitzMax Forums/BlitzMax Beginners Area/UDP Send and Recieve

Moogles(Posted 2006) [#1]
Hi, Im new here. Although I've been using blitzmax for a bit. :)
I tried to connect to a server and send a string through UDP and recieve the string the server sends. I see in my packet analyzer program the server responds, but i cannot seem to get the string recieved in BlitzMax.

Heres my code
Framework BRL.Socket
Import BRL.SocketStream
Import BRL.StandardIO

Global serverIP = HostIp("83.149.87.203")
Global port = 7778
Local socket:TSocket=CreateUDPSocket()
ConnectSocket(socket,serverIP,port)
Local stream:TStream=CreateSocketStream(socket,autoclose=False)
WriteLine(stream,"\info\")
Repeat
Print ReadLine(stream)
Until Eof(stream)
CloseSocket(socket)


Is there anything Im doing wrong?


Moogles(Posted 2006) [#2]
Bump! Doesnt anyone bother to help around here? The docs are bad enough but shouldnt the community give some help?


tonyg(Posted 2006) [#3]
Don't know the exact answer but what happens if you get rid of the networking stuff and use simple streams.
As I got the same problem as yourself I did the following...
stream:TStream=OpenStream("TEST.txt")
'stream1:TStream=OpenStream("TEST.txt")
For x = 0 To 10
	WriteLine(stream,"Hello")
Next
Print StreamSize(stream)
'CloseStream(stream)
For x = 0 To 10
	Print ReadLine(stream)
	Flip
Next
CloseStream(stream)

From this it seems you can not write and read to/from the same stream even with openstream.
If you use a different stream for the same url then it works OK. Not sure how this would equate to your socket example but might help.


Moogles(Posted 2006) [#4]
hmmm. well ill try what your suggesting. but i read that openstream is for an url:Object only. thats the problem. ill try getting it working. your the only one replying to me and helping. thanks :). do you think this is a bug? shouldnt mark or the other BRL show us the correct code?


tonyg(Posted 2006) [#5]
There's examples of this working in seperate client/server code so it's possibly the same problem as the 'normal' stream.
Not sure why it lets you use Createsocketstream with tstream as it should return a tsocketstream.
Anyway, I'll try a bit more later.
P.S. Generally, this is a very quick, very helpful community. I'm guessing, in this case, nobody has much advice or are busy with other things.
P.P.S Possibly a bug because Dirk Krause did something very similar here successfully.


Moogles(Posted 2006) [#6]
nevermind now. i was "told" i'd have to make my own module to make it work properly. the one supplied with blitzmax doesnt work so i have to find a new way of doing it. oh well.


FlameDuck(Posted 2006) [#7]
It's not so much that it doesn't work, so much as it's not designed for it.


Moogles(Posted 2006) [#8]
designed for what? basic UDP communication? i dont see how something simple as recieving text from a server can be so hard to implement. I've been trying to read the modules and understand the functions now. maybe ill try modifying mine. :@


FlameDuck(Posted 2006) [#9]
designed for what? basic UDP communication?
The User Datagram Protocol is designed to send a datagram from one IP to another, and thus is not immediately suited for streaming purposes. There is no guarantee that data will arrive in the same sequence it was sent, if at all. There is no traffic, or congestion control, to ensure that the sender does not overwhelm the host. Additionally, since it's a connection-less protocol, there is no way for the Network Interface to determine which datagrams are related, and which aren't.

i dont see how something simple as recieving text from a server can be so hard to implement.
It isn't. You just chose the wrong tool for the job.


Moogles(Posted 2006) [#10]
The User Datagram Protocol is designed to send a datagram from one IP to another, and thus is not immediately suited for streaming purposes. There is no guarantee that data will arrive in the same sequence it was sent, if at all. There is no traffic, or congestion control, to ensure that the sender does not overwhelm the host. Additionally, since it's a connection-less protocol, there is no way for the Network Interface to determine which datagrams are related, and which aren't.

Its not streaming. Its just recieving.
sending 5 bytes of data and recieving less than 200 bytes back is streaming anything.
And yet In my packet monitor I see the exact data being recieved. And in order.
'http://img472.imageshack.us/my.php?image=whatthe0qh.png'
Look there.

It isn't. You just chose the wrong tool for the job.


if blitzmax cant recieve a text line or string properly. what can it do? why is the udp module included? I paid for something that doesnt work. i know that blitzmax is designed for games and x-platform but all im saying why cant it do such simple things. Someone show me a UDP example that works. i just think that they cant be bothered to fix it.

If i could get a refund on blitzmax. id delete my account and files straight away. the access to the forums are ok. and there are nice people like assari making websites for new people like me to understand. as for the program itself. its just a DIY job. IF THERE was a post
or document showing how to build your own module using C++ files I would attempt it. but there isnt. I chose blitzmax to not have to go through the long process of C++. This UDP thing doesnt work so Im told to write my own custom streams. pff.


FlameDuck(Posted 2006) [#11]
Its not streaming. Its just recieving.
You're using CreateSocketStream.

if blitzmax cant recieve a text line or string properly. what can it do?
It can. Try picking a connection oriented protocol. Like TCP. Streams rely on an 'end-of-stream' mechanism to work. With UDP there is simply no way to reliably provide such a mechanism.

why is the udp module included?
So people can send UDP datagrams accross a network.

Someone show me a UDP example that works.
Okay. I'll post one when I get home.

If i could get a refund on blitzmax. id delete my account and files straight away.
Try e-mailing BRL. I know they've offered refunds in the past (ask Noel).

IF THERE was a post or document showing how to build your own module using C++ files I would attempt it.
Here you go.


QuietBloke(Posted 2006) [#12]
Id be interested in a simple example of how to use UDP in BlitzMax. Ive searched through the online help but cant find any help or command that will send / receive data with it.
Im sure years ago in one of the old blitz's it was as easy as createUDP and then just using something like writestring and readstring... though it was a long time ago and I dont have it installed anymore.


Moogles(Posted 2006) [#13]
Thanks FlameDuck. Ill try this Mod Writing. Still need to find me a working UDP example :)
Sorry for being angry. i just wished this could work.


FlameDuck(Posted 2006) [#14]
Still need to find me a working UDP example :)
True. Unfortunately the code I have is part of a much larger project, and has several semi-serious dependancy issues (I wasn't previously aware of). I'd send the whole source package to you, but it's about 600KB of sourcecode, which you'd have to sift through, most of which will probably only be marginally interesting to you.

Maybe I'll get some time at work tomorrow to write a shorter example of working UDP communication - right after I finish on the non-linear diff tool.

i just wished this could work.
Don't we all. BTW you might want to try your luck with that 3rd party network library thing Mark recently added to BlitzMAX. ENet or something? Might be less frustrating.


Yan(Posted 2006) [#15]
.


tonyg(Posted 2006) [#16]
I'll throw this in as well but disregard if it's irrelevant.
It mentions TNet but the webpage still lists Bmax 1.12 so not sure whether it's being developed.


Moogles(Posted 2006) [#17]
actually its not irrelevant. its some help. ill see if tnet can recieve any info from that server. i dont know about enet though because doesnt it only allow connection to other enet servers?. im now waiting for the C++ compiler to finish downloading so i guess ill keep learning how to use types. :0