PDA

View Full Version : more network connections simultaneously



cmeliak
6th June 2006, 21:07
hey guys,
i'd like a following thing to do.
imagine server <-> client application. they communicate through QSocket. I'm sure you all know example from http://www.codeskipper.com/article/3/

now i'd like to do following:
- open one connection for like a chat window ( it is already in the example)
- temporary open hiden connection for sending some files, but on the different socket/port ???

I don't really know how should i do it. i think i didn't really understood principle of connecting through sockets :confused:

could anybody sketch me please how could it work?

zhank you guys.

Cesar
6th June 2006, 22:38
What do you mean by saying "hidden connection"? Hidden from whom?

cmeliak
6th June 2006, 23:07
i mean i want to send commands from my client to server on the background. if client push the button for some status message for example, it should send "status command" to server and client gets some status back from server application. but this should be done sepparately from "chat connection". i need just have some additional connection paralel to chat connection.

cmeliak
6th June 2006, 23:18
i do not really know how to describe it :crying:

may be different. i have 2 connections in one process for example between server and client application. qt gives these connections 2 different ports. Am I correct?

I connect one signal to send data through port #1 and other signal to send data through port #2. How can server application decide from which signal i send the data? because i would like to send processed data from server back using the same port as sent

i hope U understand:(

wysota
7th June 2006, 00:33
But what exactly is the problem? What keeps you from simply making a new socket object and opening a connection there just like you did with the first one?

cmeliak
7th June 2006, 22:33
i can add a new socket and open it. that is no problem. means i will have:

socket #1
socket #2

then i send some text through socket #2, server application will process this text and send back modified text. so now, how can server recognize that it should send data back through socket #2, not using socket #1?

i want simply have two separate channels for communication between server and client

jacek
7th June 2006, 23:36
how can server recognize that it should send data back through socket
The same way as the client, because it will also have two sockets.

cmeliak
8th June 2006, 00:03
ok. if i understud it well, i should create 2 sockets on the client and two sockets on the server. so, but how to force client to connect to certain socket? actualy server creates socket for each connection. i am really confused guys. do you have some picture for me? :o

jacek
8th June 2006, 00:20
how to force client to connect to certain socket?
You can't. Client connects to a given port and it even doesn't know what program listens there.

You could use different ports (like FTP does), but IMO it isn't necessary. Just add another command to your protocol that will allow clients to choose connection type. For example "CHAT MODE" would switch the connection into chat connection, while "CONTROL MODE" --- into connection that controls the session.

You will also need some kind of authentication mechanism, so that can tell which connection belongs to which client (note that user might start multiple instances of a client program on his computer).

But do you really need two connections?

wysota
8th June 2006, 01:17
You could use different ports (like FTP does), but IMO it isn't necessary. Just add another command to your protocol that will allow clients to choose connection type. For example "CHAT MODE" would switch the connection into chat connection, while "CONTROL MODE" --- into connection that controls the session.

Or provide control sequences made of unused characters (and escape them during normal transmission) so that you don't have to handle different "modes".

To be honest this should be simply realised as urgent data (TCP) but I doubt Qt allows one to send/receive them.

Edit: Another way could be to provide "commands" between the client and the server and treat chat transmission as another command in network traffic.