View Full Version : Something for starting with TcpUdp module
ErosOlmi
12-01-2007, 16:27
In a recent post (http://community.thinbasic.com/index.php?topic=449.msg2332#msg2332) with kryton9 I talked about possibility to use network to exchange data. Maybe to develop specific applications or maybe exchanging data in order to develop games with networking functionalities.
In any way, just for starting, here it is a piece of code that shows how to exchange data between two computers over the network.
It uses UDP protocol, more easy to be used and no need to be connected all the time to work.
This example just implement a simple chatting console able to send and receive chatting data.
How to use:
execute it on two different computers
tell each other the respective IP address
use F1 key to send data
It can be implemented a lot with many functionalities and using UI module to give more professional look but here we are to understand the networking side of the project and possibly implement TCPUDP module with new native functionalities.
Eros
ErosOlmi
12-01-2007, 16:39
Forgot to say that if you have installed some firewall on your boxes, you have to authorize ports used by this example otherwise net packets will be discarded or blocked.
This example works over any pct/ip network.
In case of different networks (like 2 PC connected over internet) if routers or HW firewalls are used, some NAT (Network Address Translation) rules must be in place inside routers in order to let public IPs been exchanged with local lan IPs.
In case internet connection is using modems the only thing to warry about is personal firewalls installed on PC.
Regards
Eros
Oh wow, can't wait to test later tonight. I have a network at home so I can test it. More later, thanks in advance!!
Eros, I tested the program. But couldn't see messages being sent between the 2 networked computers.
I enabled a port for each on my linksys router and they each have assigned ip's.
192.168.1.46:6112 the other is 192.168.1.34:5100 both ports granted UDP permission and no other firewalls used.
I also tried both on the same port number and that didn't work either?
This is all on my side of the network, not going out over the internet, but through my router/switch at home, if that helps.
Let me know of anything else to try, it will be neat to get this going :)
ErosOlmi
13-01-2007, 12:15
Hi kryton9,
I've tested the script on different situations and all was ok. I've tested at work where we have many nets and at home were I have a DSL router + switch and just one network (192.168.0.0/255.255.255.0) and all went fine. If you are on the same net like you (192.168.1.x) there should be no need to configure your router because in reality you are using your router as a switch (so usually no filters takes place). Different would be if you have some local vLan.
In my tests all PC have Zone Alarm Pro installed but instructed to let local LAN pc to get through.
In any case, to test, you just need to leave the same port on both PC (more easy for starting) and specify the other side IP.
So, you have to tell to PC A which is the IP of PC B and to PC B which is the IP of PC A.
If it is not working, more likely it is some software blocking on one of the two PC.
If you have some security suite, this can be the problem. Many all in one security suites like Norton Internet Security or similar are in reality little personal firewalls.
Also WinXP SP2 has firewall but usually it lets UDP to pass.
I can try to add some auto-discover functionality to script broadcasting some messages and waiting for responses but in any case if you are protected on the used UDP port this will not solve the problem.
Ciao
Eros
Eros, no software firewall is running. I just use my linksys as my hardware firewall.
I have fixed ip's assigned to my computers and am able to send files back and forth.
Here is my scenario:
Main Computer 192.168.1.46 port 6112
Notebook 192.168.1.34 I tried port 6112 and also own port of 5100.
I ran your script on both computers.
It gives the correct information for the computer I am on and also for the other computer on each one.
Maybe I should not use any port and let it use the default, will test that before going to bed, as it just occured for me to try that :)
.... will write in a minute ...
Ok just using the default ports, which I didn't try before, is working one way. That is I started my Main computer first and then my notebook and I can send from Main to the notebook, but not from the notebook back to the Main computer.
It is cool, will play with it more when I get back up, very sleep now :)
Tried it one more time, it is working now. I am just using the default ports and it works :)
Before I didn't use the default ports, but assigned my own.
ErosOlmi
13-01-2007, 13:15
Good.
Important is to make little steps to understand possible problems otherwise othe subtle reasons can be the cause of networking not working.
On netwroking many aspects can be the cause of blocking problems.
In the meantime, try to see souce code if all is clear. If you do not have time now, no problem. Important is that you was able to run it fine. I will take some time to try to better comment code, to add a more clever/clear user interface and to try to implement auto-discover PC already executing script over the LAN using broadcast messages.
After all is clear, networking possibilitiers are infinite. We can create a personalized protocol or adhere to some ideas already developed by other. I this a little chat script can be a good example to create a gaming communication protocol.
Anyhow, not high priority. Games must come first.
Ciao and thanks a lot for your time spent using thinBasic and for your positive attitude, always.
For us it is a precious present.
Eros
Eros, sorry I missed your reply here. I noticed lately that Show Unread Posts Since Last Visit is not working properly for me.
The last few days I have been using the Home Button and then looking at the right side of the window for the latest messages.
That is how I noticed this one tonight.
I wonder if anyone else is noticing strange problems with that feature?
thinBasic just amazes me each day. You guys really did an awesome job so far, when I look at all the commands and modules, it just boggles my mind!!! Thanks!!
I noticed here and on gamedesignnovice.com that the Show unread posts since last visit are not showing all the posts not seen. This might have something to do with Simple Machine Forums. I have a hunch it must be maybe how many it can show on 1 page perhaps?
It would be neat if both forums had the first page list all the new posts so it would be easy to see them and not miss anything. I noticed I am missing things or a few days late in replying many times because of this. Hope it is something easy for you guys to setup.
ErosOlmi
16-03-2007, 09:05
Yes I noticed too.
That's why in thinBasic first page forum there is the RIGHT side showing all the new items with a "New" little icon on them.
Do you see the right area in first forum page? If not use the upper +/- open/close areas.
Ciao
Eros
I do and have been using the area on the right Eros, but I think sometimes posts are more than can show there and I don't see them till a few days later. Or by searching around.