I have a custom TCP Server listening on port 5888(dummy port). The proxy server listens for incoming connections. When the proxy receives HTTP request for certain pages, it should relay it to the main server on port 80.For other page requests the proxy is required to send data to the main Server on port 8081.
The port 80 is used to service the HTML Pages where as the port 8081 is used for streaming data to the clients.
I am able to receive the incoming connections on the proxy and then read the data from the clients. After reading the data, I can determine which port to connect to on the main server for sending the data.
I am stuck at deciding how to connect on 2 ports for sending the data from the clients to the Main Server?
In that case you either need 2 socket connection objects to the same IP on the different ports (this is legal), or you have one connection object which reconnects according to the port you have to deal with.
Depending on how often you have to switch connections the latter version might have a huge overhead, plus the first one allows you to send data to both ports virtually simultaneously.
You need to stop thinking of your program as a server. After you have received the connection, read the data, and decided what port to send it to, shift gears and start operating as a client would.
Just open a new connection to "localhost" on either port 80 or 8081 and re-send the data you received as if you were the original client.
Your client is connected to the proxy server on port 5888 so no matter from what real server (Web or streaming) you take the data, you are going to provide the data to the client using port 5888 only.
It seems to be a not so practical solution. I am assuming here that you are trying to achieve a kind of control port and data port structure where one port is controlling the streaming from another port.
Just creating two sockets is sufficient for obtaining data from two servers. Here you will have to manually create a protocol which your client understands as you are going to provide both html and streaming data to the client using single port.
Related
is it possible to have one socket router that would pass incoming sockets to socket servers?
I need this because I want to have multiple servers for handling sockets but only one port for clients to connect to. so if one of the servers goes down, router would send the socket to other healthy socket servers.
Is this even possible and how? or any other solution for my problem?
Yes this is definitely possible, and is used very widespread.
Basically you need to have one TCP server running on that one port you want clients to connect to. Then you can listen for connections. When a connection is established you can reroute packets to other servers (you choose).
Listen on a port with your main server
Accept connections as they come in.
When a connection is opened, read the data in another thread. Take that data and send it to the other server you want to.
Basically, it is a proxy.
I need to bridge traffic from one port (say port 3000) and send it to a new port (say port 4000) and have full bidirectional TCP support.
How should I go about solving this? Should I use the socket class or the TCPClient class?
Would this be as simple as sending the stream of data from one TCPClient to another?
Is there anything else I should be considering?
You program needs to act as both a server and a client:
It should act at a server regarding port 3000, where your program receives connections. Each time you receive a new connection you yourself create a new connection to the actual server on port 4000. Keep these two connections (the one initiated on port 3000 and the one you created to port 4000) together, so you know they are a pair. When you receive data on any of these connection, just send it on the the other connection in the pair.
i am wondering how tcp servers work because there is no multicasting. I am interested in using tcp for my game since it won't require to much packets to be sent like some other games. It still needs to have a client / server architecture though.
Since there is no multicasting, is there just a loop to send everything directly from server to client for every client? Is this what minecraft does (cuz i read it uses tcp)
it was my understanding that only 1 socket can be bound to a port. With udp, the server socket can accept connections from IPAdress.Any, so it can receive information from all clients. Since TCP is connection only, how would this work? Can multiple TCP connections be made on the same socket?
Only one listening connection can exist per port on the server. However, many clients can connect to that one listening port. A "Connection" under the hood is the combination of ServerIP + ServerPort + ClientIP + ClientPort, also the client port does not need to be the same every time (only the server side port needs to stay static), the OS chooses a random high number port and give that to the client side for the connection. That is why you can have many outgoing connections on a client but only one listening connection on the server.
Look at this page for a example on how to set up multiple connections to one port.
How can I send data from my C# socket program to my clients?
Currently I have two programs, server and client.
I start my server, then my clients connect to server, in this way they are connected together, but now I want to send directly from server to client?
As my client cannot start its own connection, of course I have IP and port of my client, how can I send data from my server to a client with known IP and port?
Thanks.
Since your clients are not computer programs you can control, you really have no chance but to contact them from the server. If your clients can handle TCP communications, you need to treat them as servers, and Connect from the server to each client (open the socket on the server side, and Connect to each client IP and port).
It's possible that your clients understand UDP and not TCP. That is actually going to be easier for you, as you only need to create one UDP socket, and use SendTo to send a data to each client (one SendTo call per client).
Let's just hope your clients aren't stuck on the Ethernet level...
I would say that COM-ports are slightly easy to communicate than implementing TCP/IP protocol on your device. Could your device read/write its COM-port?
What is the best way of reading, changing, and resending UDP communications?
For instance i have a server application that tells a master server it's alive sending a packet over UDP on port 3209. It sends out "I'm alive, my ip is xxx.xxx.xxx.xxx and I have currently 3 clients connected to me." the master server then responds, "Hello xxx.xxx.xxx.xxx i see you there."
Whats the best way of MITM (Man In The Middle) of the server sending its packet to the master server? I would like to be able to change "I'm alive," to something like, "I'm changed," or even "currently 3 clients connected" to "currently 0 clients connected"
When trying to make a new UdpClient to the port the server is on i get a "Only one usage of each socket address (protocol/network address/port) is normally permitted" exception.
you mean packet analysis?
You should do two things:
Discover real protocol of
interserver communication. They are
comunicate over UDP but structure of
the data trasfered is not the
network protocol. You should
discover data structure are
transfered between servers
Decide on wich side you are going to
operate with packets. If you are on
one of the servers sides, you can
write filter driver wich would be
change data before it will be
sending or before it will be
recieving by application. If you are
not in the serber side I dont kwnow
hot to intercept network packets
UDP has no integrated security and is not connection oriented so in this case It will be much easier.
You can forge the source IP in the IP packet (no real problem doing that) and just sniff the UDP packets sent to the real IP server. The main problem here is avoiding the main server to receive the real packets from the real client. For that you'll have to tamper with the routing scheme which is not really easy to do...
I ended up writing a program to listen on the port that the server was sending to. I then resent all the data to the master server with the values changed that i needed. When the master server responded back i then sent that data back to the client application. Nor the server or the client application know there is a server in the middle changing the data.
Thanks for all the replies!