Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Multi-client network communication?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
botcrusher




PostPosted: Wed Sep 02, 2015 11:38 am   Post subject: Multi-client network communication?

What is it you are trying to achieve?
Networking with multiple clients.

What is the problem you are having?
Multiple clients can connect to one server, but only the first ever receives more information. What i really want to do is have a server cleanly be able to communicate with multiple clients, without some of the complex workarounds I've starting coming up with in my head.


Describe what you have tried to solve this problem
Not quite sure how to proceed, but i tried reconnecting clients, both over wan ( i have nice friends ) and over a simulated lan thanks to a small army of slitaz virtual machines.


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
I'll edit this in in about 5 minutes

Turing:


<Add your code here>



Please specify what version of Turing you are using
Turing 4.1 (not 4.1.1)
Sponsor
Sponsor
Sponsor
sponsor
DemonWasp




PostPosted: Mon Sep 07, 2015 6:34 pm   Post subject: RE:Multi-client network communication?

This might get a bit complicated. Plus, if you're at the point where you're getting into networks, then you are also at the point where you could start picking up a better language than Turing.

If I recall correctly, Turing is kinda goofy about its networking. Normally, you can open a 'listen' socket and accept multiple connections on that same port. In Turing, you need to listen on one port, get a connection, then listen on another port. Unfortunately, that means your clients have to know the next port.

The best workaround I was able to come up with was this:
1) Listen on a specific port, the "initial" port.
2) When you get a connection on that port, immediately send the client an integer that gives them the number of the port they should reconnect to.
3) Listen on that second port until you get a connection.
4) Go back to the "initial" port so another client can connect to that port.

I tried to test that but my Turing kept crashing. If you really want to get this stuff working in Turing, remember that you can generate standalone executables for the client and run the server from within Turing itself -- that should let you launch multiple clients from your own machine.

I think that the underlying reason that Turing is so bad at this is that Turing is providing a very poor abstraction over Berkeley Sockets / BSD Sockets, which let you listen() to a particular interface+port combination, and accept() multiple connections to that combo. Turing combines the two, which means you can't reuse the port you listen()ed on to accept() a second connection. Bleah.
botcrusher




PostPosted: Mon Sep 07, 2015 7:36 pm   Post subject: Re: Multi-client network communication?

Alright, thanks. I was thinking something alon the lines of a "dummy" connection used to redirect clients.
As for the crashing, try turing 4.1 It seems to be some bug in 4.1.1+ from my testing.

Yes, i will be moving on, the idea was to make a last hurrah Smile
And well, school starts up tomorrow, and i got computer science which just so happens ti be starting python 3.x
agnivohneb




PostPosted: Fri Sep 11, 2015 10:00 am   Post subject: RE:Multi-client network communication?

I had created a program back in 2007 using turning that did just this. I modified the NetChat.t example to include multi chat and called it NetChat 5.0 posted it in the forums and now the links no longer work so I can't show you that code. However the method DeamonWasp mentioned is exactly how I did it.

I wrote a server program and a client program. The server would just relay messages to all clients and clients would just wait for the server to send them something new.

SERVER: Listen on port 5000
CLIENT: Connect to port 5000
SERVER: Check list of available ports (5001)
SERVER: Mark port 5001 as inuse
SERVER: Listen on port 5001
SERVER: Tell client new port 5001
CLIENT: Disconnect from 5000 and connect to 5001
*REPEAT FOR ALL CLIENTS TO CONNECT*

CLIENT: Input from user "hello"
CLIENT: Ammend username "User1: hello"
CLIENT: Send "User1: hello"
SERVER: Recive message "User1: hello"
SERVER: Loop array of inuse ports
|---->Send message "User1: hello"
CLIENT: Recive message "User1: hello"
CLIENT: Display message "User1: hello"

Notice how the server will send the message back even to the originating client. This is a check for the client. If your message didn't show up on the screen then it never made it to the server and back.
MrMac




PostPosted: Sat Sep 12, 2015 11:19 pm   Post subject: RE:Multi-client network communication?

"post any relevant code"
doesn't post code.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: