Threaded TCP connection
BlitzMax Forums/BlitzMax Beginners Area/Threaded TCP connection
| ||
I've been messing around with TCP a couple days now. Does anyone know how to achieve real threading, in such a way that your game does not hang when it for instance does a writeline/sendline? Currently I have readline/writeline in my mainloop (through a server and a connection class, connection.update()), and with writeline, it will lock up completely, so I've resorted to using readbyte only when there's data on the socket. Then it doesn't lock up, but it's still not real threading, and I can't figure out how to do it just now.. Can anyone help? Basically I want to be able to fire off a couple lines to a stream, without worrying about a slowdown in my game. (Yes I know of tnet/bnet/whatever mod, but I'm trying to learn the basics here, and I know UDP should be used for games, but the purpose here is sending data :)) |
| ||
Does anyone know how to achieve real threading, in such a way that your game does not hang when it for instance does a writeline/sendline? You can't. BlitzMAX doesn't support threading yet. |
| ||
It's not even possible by "faking it" then? |
| ||
Drago has written a real threadding mod for an old version of bmx. Don't know where you can download / get it though... :( |
| ||
It is useless. GC is not threadsafe so using the threading module on a system with more than 1 core (HT or real dual core / dual processor) will guaranteed lead to fatal errors! and faking is only possible through timed programming so at best through eventhooks and a timer |
| ||
Ok I think the word is not threading then. What I mean is for the connection to occur in the "background", in such a way the main game itself will not stall, even for a miliseconds.. Is that possible? |
| ||
No Or I should say: no, not with one app There is the possibility to create a "connection app" that you start through CreateProcess and that writes all needed data to console from which you can read it thought :-) |
| ||
So I guess that's what they have done in bnet/tnet etc. |
| ||
So I guess that's what they have done in bnet/tnet etc. No, not in TNet, and I guess not in BNet either. Even TNet stalls when you initiate a TCP connection. That is why I do not use Peer to Peer TCP yet. However if the location you connect to is close, the time to connect is just a couple of milliseconds, so you might not notice. UDP on the other hand is running while connecting without problems.If you want to learn how to do it yourself I could send you the source to "TNet_Core". Which is a wrapper for the blitzmax socket functions to make the creation and working with sockets easier. Mail me and I will mail it to you (for free). It is what TNet Advanced is built upon. |
| ||
Hey Wave, thank you very much! I will mail you right away! |
| ||
this might help: 1. use UDP 2. send tiny amounts of information per 'write' 3. do error checking in your program (TCP error checking overhead is expensive) |
| ||
I stated in my first post I won't be using UDP for this purpose, as it is to send data that must be sent/received properly. |
| ||
2. send tiny amounts of information per 'write' By 'tiny', he means more than 64 bytes, and less than 256. I stated in my first post I won't be using UDP for this purpose, as it is to send data that must be sent/received properly. You can roll your own virtual connection, sequencing scheme, sliding window, reliability and congestion control on top of UDP if you want. |