UDP example
BlitzMax Forums/BlitzMax Programming/UDP example
| ||
Does anyone have a working UDP example? Nothing in Code archives. I searched, found nothing except people trying to get UDP to work. Any help here? Thanks :D |
| ||
depends on what your trying to do. i think blitmzax can only communicate with its own udp sockets rather than universal ones. read my post. http://www.blitzmax.com/Community/posts.php?topic=57391 its got a basic example of making udp work. but i think it can only connect to another blitzmax app and send and recieve. |
| ||
I can receive as a server, but I cant narrow it down to what IP:port im getting it from. I cant send as server. I can send as client, and I believe receive although I cant test receiving. =/ Kinda odd, how theres no UDP code archives at all, nothing. |
| ||
Use SocketRemoteIP( socket:TSocket ) on the socket that the client is connected to. i think thats the one. the name makes it seem the logical thing to use. although im not sure. |
| ||
That only returns an IP though, can't set it. I can send to a server, use ConnectSocket. Then just write to the socket stream. That's not too UDP like :P Can't switch to a different IP without having to destroy the socket and stream. |
| ||
make a new connection with a new socket and stream. ;) |
| ||
Don't try to use socket streams with UDP sockets, it just isn't going to work. Either use one of the freely available networking modules available (BMax includes one, well, two really as GNet is a high level mod based on the enet mod), or use raw sockets. It really depends on what you're trying to do. |
| ||
or use raw sockets and how would we do that sir? :) |
| ||
Use my BNetEx http://vertex.art-fx.org/bnet/bnetex162.zip (object orientated) or BNet http://vertex.art-fx.org/bnet/bnet160.zip (BlitzBasic like) Examples are includet. You can use the code too, to understand, how udp work with BMax. Raw Sockets are not easy to use. cu olli |
| ||
When I said 'raw sockets', I meant via the BMax sockets module as this makes things easier. I'm by no means an expert with sockets but they seem fairly straight forward, it could well be a case of 'ignorance is bliss' thought. @Moogles - As you asked so nicely, here's simple example you may recognise... ;o) A more 'correct' way is probably something like... If you're only going to be doing simple stuff, like above, the network libraries are overkill IMHO. If, however, you're going to be doing anything mildly useful then use one of the libraries (I haven't used BNet myself, but it seems to be very highly rated by those that have). |
| ||
ZOMG!. You made it work!! :P Thanks Ernie! :) Vertex I tried Bnetex too. its nice but it couldnt read that text from the server like enie's example does. thanks ernie! er.. sir! :) [edit] btw the way. your "proper" way doesnt work for that example. :) ill use the improper way thanks :) |