send data between two server sockets - sockets

I have to make an app using C/PHP sockets on linux that sends data from one socket to other socket, like this.
I have server (server_hosted) hosted somewhere with an IP or domain name. It is running web application.
I have another server (unknown_server) running at my home (unknown IP).
Client send some information through web application hosted in server_hosted to another server running at my home (unknown IP).
I need a way to established a connection between server_hosted and unknown_server.
I was able to make connection between both using TCP socket. I made server_hosted as server listen to certain port says 8080 and unknown_server as client, which make open connection to server_hosted.
The problem comes when I have multiple unknown_server at my home. How can I made connection to same port? How many client can TCP/IP support?
Any ides how to make tunnel or connection between server_hosted and unknown_server.
Is possible to do with curl or socket any better ideas?

Related

How to set up a client/server connection using port forwarding

I created a multi-threaded client/server application that can send messages to each other at real time. Everything works perfectly, but I want to be able to send messages over the Internet. From what I understand, I need to do port forwarding to be able to make my server reachable for the clients. I then set up my port forwarding options by providing a port (9991) and then my Macbook Air's IP Address (192.168.0.1).
I then tried to connect to my server using my public server IP (let's say 197.132.20.222) and it didn't work. I then tried to see if the port forwarding worked by using this website: https://www.yougetsignal.com/tools/open-ports/ and I realized that the connection was closed. I also tried the command nc -vz 197.132.20.222 9991 while running my application and the connection is refused.
I'm using a JavaFX application, and for my server side I use a ServerSocket with port 9991. For the client side, I use a Socket and set the IP Address to my public router IP Address, and I tried to connect with another PC using mobile data to use a different network.
My firewall settings are turn off, so I really don't know what is blocking my application to connect to that port. Could it be my ISP is blocking connections? I just don't understand why my ports are blocked even with no firewalls enabled.

Client and Server connection with different port numbers?

I have set up a client and a server using sockets in python where my client sends data to the server, servers performs an operation, then returns some data to the client. Originally both the client and server were to have the same port number (9999). My issue currently is that I have to change the port of the server to 19999, and when I try to run, it does not work. The client is able to send data if its port is also changed to 19999, but it does not work if client is 9999 and server is 19999, which is what I need. New to networking systems so would appreciate any useful links to information or advice.
pic of client (left) and server (right)
Normally, clients will use an ephemeral port for its local port, and connect to the server port. Your client code is attempting to connect to port 9999, which is not the server port, which explains why it is not working. You need to connect to port 19999, since that is the port the server is listening on.
Using an unbound socket causes the client to choose an ephemeral port for its local address when making a connection. If you want the client to bind to a specific port, use bind before you call connect.
# bind locally to 9999
local_addr = (host, 9999)
s.bind(local_addr)
# connect to 19999
remote_addr = (host, 19999)
s.connect(remote_addr)

Outgoing connection proxy for http ingoing traffic

I've got two applications, a client and a rest server on two different servers.
The server is in the DMZ, and the client is on a hosted server.
My entreprise IT department wants to have only ontgoing connexions to the hosted server so that the firewall only sees outgoing connections.
They sugsets to have the following architecture :
hosted dmz
Client <---------------> Server
Proxy server Proxy client
1) Proxy server opens a tcp socket
2) Proxy client connects to this tcp socket permanently
3) http requests can be forwarded from client app to rest server app through the tcp connection
Do you know any software that implements such an active proxy mechanism ? (eg apache, nginx...)
Is it more secure that just opening port 80 for the web hosted machine ?
Do you know any software that implements such an active proxy mechanism ?
There are a variety of solutions: from netcat (nc) to socks5. I suggest you to start with netcat, since it is much easier to understand and configure.
Is it more secure that just opening port 80 for the web hosted machine ?
Yes, it is more secure that just forwarding port 80 to DMZ, since you are punching a hole in firewall just for the specific flow.
On the other hand, adding an access list on top of 80 port forwarding should make it even, but there might be other issues, like corporate politics, hardware limitations etc...

C socket: TCP/IP multiclient: Chat and transfer file on the same port

I'm writing a C socket program to chat and transfer file between multi clients. There is a lot of topic about TCP client-server but I didn't find any solution to solve my problem. I would like to ask how we use just one port for both connections.
Here is what I've tried and it works well, but I'm using two separate ports for chatting and sharing:
*Server:
1) create a socket and bind it to port 1234 for chatting
2) create another socket and bind it to port 4321 for sharing file
-> we have two listen sockets waiting for clients to connect.
*Client:
1) Create a socket and connect to port 1234 of server //chatting
2) Create a second socket and connect to port 4321 of server //sharing
--> for each client, we need two socket connect to two ports of the server -> we can chat and share file at the same time.
The problem is it seems not efficient and face up to some problems:
a) Use two ports -> require the server open port forwarding on both
b) If we have multi clients connect to server at the same time, server will detect wrong the chatting and sharing socket of two clients
I also found a suggestion to use a socket and mark flag/header the transmit data then we can separate chatting and sharing data. But if the buffer size of client and server is different, we can't receive full of packet each time to detect the type of receiving packet.
What is the best way to use one port for chat and share concurrently?
and if we integrate more services like stream music, video,etc. How to use multi connection on the same port?
If we use multi connection on the same port how to detect type of connection (chat or share) when a new client is accepted?
Thank you,

Changing local port of a socket client

I have a simple TCP socket client and server application. They are communicating using IP = localhost and port = 33367.
I'm using SocketSniff to examine my packets going through localhost. While sniffing the client app, I noticed that every time I'm sending a packet to the server in the same process, the "local port" is changing, while remote port is always 33367.
So, is it possible for the client apps to send their data through a fixed port (if so, how in C#?) or do they have to get assigned a different port each time?
You can bind the socket before calling connect.