использование сервера для управления TCP-соединениями - PullRequest
1 голос
/ 02 сентября 2011

У меня есть серверное приложение и клиентское приложение для отправки и получения файлов между компьютерами.

Вы можете пропустить эту часть:

My algorithm is as follows:

`server:  start listening for connections

client: establish a connection with the server

server: start a thread where that thread consist of a method listening for data send through the network stream

client: also start listening for data on a while loop runing on a separate thread.


\\so far if the client sends a byte array through the connection netwrok stream the server will receive it.

\\ also in each while lop the client and server there is a switch statement. if data received commes with the string "<file>" then it will start listening for the transfer of a file


client: send the string "<file>" to the server and start listening for that file on a different method.

server: because it receives the "<file>" keword it exits the listening loop and sends "<ok>" reply

.... so the talking between server and client keeps going ...........`


also the server is running yet more other threads such as still listening for
new connections. maybe another client want's to connect to it. so every time 
a client connects the server, the server will start doing the same process 
again on a separate thread (listening for new connections). 

Таким образом, вы можете видеть все, что получает, отправленный через сетевой поток, получает другое приложение.

Так что все отлично работает, когда соединение установлено

Теперь подумайте о том, что должно произойти, чтобы установить соединение с компьютером A, который находится в доме, а компьютер B находится в офисе в другой сети. Примечание (компьютер A и компьютер B имеют доступ в Интернет). скажем, вы хотите, чтобы ваш компьютер A был сервером, а компьютер B - клиентом. Так что вам придется запустить сервер. отличный сервер сейчас работает. Затем вы запустите клиентское приложение. Вам также придется указать маршрутизатору в доме переадресовывать весь трафик с порта X на этот серверный компьютер, чтобы компьютер B мог его найти. Как только вы это сделаете, компьютер B сможет установить соединение. Если на следующий день у вас другой IP-адрес, поскольку у большинства из нас нет статического IP-адреса, вам потребуется изменить этот IP-адрес на клиентском компьютере, чтобы установить соединение. так что это может быть довольно сложно и не дружелюбно. Также вы можете захотеть, чтобы ваш офисный компьютер был сервером, потому что он всегда может быть включен, но, возможно, у вас нет доступа к маршрутизатору, поэтому вы облажались.

Решения:

1)

on my house call my internet service providers and pay to get a static IP. 
I have not developed an algorithm but basically now computer A and computer 
B will be clients and they will be connected to my computer at my house. 
(on my house I will have to configure the router obviously to do port forwarding).
so know if computer A wants to send a file to computer B the server at my house 
needs to have those to connections. the connection between computer A and the 
connection through computer B. If something get's sent to the server at my 
house from computer A then sent that to computer B and vice versa. 

problems with this solution is: The upload speed at my house is very slow therefore
the transferring of files will be slow. also I don't know if my network at my 
house will be able to manage multiple connections. 

2)

step 1)
Host a website from my home still getting a static ip address. this time I also 
have to get a domain so that users can remember me. so let's say that I am able
to host this website hosted on my house as somedomain.com  . soon you understand 
the purpose of the website....

step 2)
I don't know that much about this it is called "UDP punch hole into firewall". 
this basically tells the router to port forward all traffic from port x to the 
server so that users don't have to open ports on their routers. I DO NOT KNOW 
HOW TO DEVELOP THIS I HAVE JUST HEARD ABOUT IT. so if I develop this computer 
A will be able to connect to computer B without having to do any configuration 
on the router which is nice.

step 3)
let's say that computer B is the server and computer A is the client that want's 
to connect to computer B. so computer B will talk to my website at my house and 
tell it that it is listening for connections on the ip address xxx.xxx.xxx.xxx . 
then the client computer will access the website at my house and see the ip address 
of computer B. now the connection is going to be able to be established.  

step 4)
If the internet IP address of computer B changes for example. then let my website 
know the new IP address. next time the client want's to connect to the server it 
will be able to find the correct IP by looking into my website.

problems with this technique: I do not know how to implement
"UDP punch hole into firewall" so that users do not have to do any configurations 
on their routers. an example of this will be helpful.

3)

there are a lot of companies out there that can host you a website. I don't know 
about a company that will let me run a c# console application on their server. 
Also I don't know if the file transfer of data going from computer A to a server 
then to Computer B is more efficient than data going from computer A to computer B. 
This solution will enable me to stop thinking about users having to configure their 
routers which is nice. 

Это приложение позволяет вам делать еще много вещей. Я знаю, что есть несколько приложений, которые позволят мне просто передавать файлы. Было бы хорошо, если бы кто-то указал мне верное направление, какую технику использовать.

1 Ответ

2 голосов
/ 02 сентября 2011

Если вы используете бесплатный DNS-провайдер, такой как DynDns free , и DNS-обновитель для вашего динамического IP-адреса, например этот , то вы можете подключиться к вашему серверу по DNS-имени, а не по IP адрес. Используя программу обновления, при изменении вашего адреса DNS-запись будет обновляться у поставщика DNS.

Другим вариантом может быть использование DropBox для синхронизации папки между клиентом и сервером, а затем преобразование серверного приложения в монитор каталогов, который ищет новые файлы, синхронизированные с помощью dropbox.

...