TCP/UDP/IP Question[s]

Blitz3D Forums/Blitz3D Programming/TCP/UDP/IP Question[s]

Adam Novagen(Posted 2009) [#1]
Hey all,

So, I'm knocking together a Chat program for some friends & me. Yes I KNOW there are a brazillion or more Chat APPs out there, but I want to make one. So there. XP

Anyway, let's say a friend & I are both online with our programs running. My IP is, say, 111.111.111.111, and my friend's is 222.222.222.222. My friend, however, is in the next town/county/state, so is no part of my LAN. Now, let's say we both have TCP servers created & running for our Chat programs, like:

Me-
ServerPort = 1234567
ChatServer = CreateTCPServer(ServerPort)


Friend-
ServerPort = 7654321
ChatServer = CreateTCPServer(ServerPort)


Both our programs are listening for messages from the other, with some code like:

Repeat
    InStream = AcceptTCPStream(ChatServer)
Until InStream


Then, my program sends a TCP stream to my friend's APP (still listening,) with something like:

OutStream = OpenTCPStream("222.222.222.222",7654321)

If OutStream
    WriteString OutStream,"Ahoy!"
    WriteString OutStream,"Anyone out there?"
    CloseTCPStream(OutStream)
EndIf


Assuming my friend's APP is still listening, would this code work, and the message be recieved? Or would I have to use UDP, or some other method altogether?


Adam Novagen(Posted 2009) [#2]
What, no tips whatsoever??


Guy Fawkes(Posted 2009) [#3]
Now u know how i feel.. u sometimes have to wait over 2 days to get a reply. just be patient.


Ross C(Posted 2009) [#4]
Poor, poor you's. I really feel for you, waiting for people to reply on this forum, where folks come (in their free time) to help those in need. Maybe i'm just having a bad day, but you really come across ungrateful.


Matty(Posted 2009) [#5]
Yes something like that would work. Have a look at my code archives entry.

And regarding 'no tips yet' - some of us live in other parts of the world. 6 hours ago, when you posted that it was 6am here.


Adam Novagen(Posted 2009) [#6]
Ross - and anyone else who's reading this - I'm sorry if I seemed ungrateful. In retrospect, it does rather seem that way, but I really didn't mean to be.

I am ENORMOUSLY grateful to all the people who help out on these forums, none of whom are reqiured to do this by any means. I don't mind waiting for an answer at all; the only time I post one of those "Anyone?" lines is when my post is in danger of slipping away unanswered, and being forgotten. I just do it to bump it back to the front. And I never do that more than once.


Ross C(Posted 2009) [#7]
No worries. As i say, probably just having a bad day yesterday...


Adam Novagen(Posted 2009) [#8]
Well, you still did have a point. Plus, I always enjoy well-placed, well thought out sarcasm. ^_^


Wings(Posted 2009) [#9]
Where is the readline command ?


Adam Novagen(Posted 2009) [#10]
Erm, probably something like...

Repeat
    Local StreamIn = AcceptTCPStream(ChatServer)
Until StreamIn

While Not Eof(StreamIn)
    Print ReadString(StreamIn)
Wend



Wings(Posted 2009) [#11]
i belive you have to rethink a little.

tcp works difirent.

tcp you open 1 stream and use it for both read and write.


Prym(Posted 2014) [#12]
I would ask a question which no response can be found in much forum pages .
Does someone can tell me if the OpenTCPstream is usable in a loop ( the main) one , for ex ) , or is it called once , as "AcceptTCPstream" ?
Thank you from a french reader ( reading all is sometimes difficult )


RGR(Posted 2014) [#13]
The best response you can get is in the code archives with many examples and answers ready to use.

With OpenTCPStream your program sends sort of a *question* like "Hello server - are you there?" and your program waits for an answer. Which may be coming immediately or takes several seconds.

Is it wise to do that 216000 times per hour in the main loop? No - because what you open you have usualy to close before using it again. You do not need 100000s of open streams - answered with logic.

Inside the loop you check if there is communication available. And if there is, then you retrieve data and send data.

Also if you see in the commandlist OpenWhatever CloseWhatever you can be sure in most cases that this is nothing to be done in a loop because OpenAnything always puts you back to the start (OpenFile OpenTCPStream OpenMovie) and this is not what you want.


Prym(Posted 2014) [#14]
Thank you RGR,
I understand that OpenTCPStream should not be in the main loop of my program ( where stream datas are sended and received ) .
But when I suppress the OpenTCPStream and CloseTCPStream commands of my code , it does not work . I have kept AcceptTCPStream in the loop ( for the player-server )