Apple Push Notifications and Port 2195 - sockets

I'll be using JavaPNS to implement my server side of things of the push notification service. I don't have control over what ports are open on the server, but assuming that all ports are open for outbound connections, do I have to also open port 2195 for inbound connections? Correct me if I'm wrong, but my understanding of TCP is that when I make the connection with the Apple server, a source port is randomly assigned to any port not being used and when the Apple server responds (the inbound connection), it will come through that source port. So, my theory is that port 2195 does not need to be open for inbound connections. Is that right?
Also, if the response comes through the random port, doesn't that mean that that port needs to be open to inbound connections? How does the firewall manage this since only a few ports will be indefinitely open for inbound connections? Does it leave the random port open only temporarily for this specific request-response session?

You only need port 2195 to be open for outbound connections (and also port 2196 for the Feedback Service).
You don't have to open any port for inbound connections, since Apple doesn't initiate the connection to your server - your server initiates the connection to Apple.

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.

TCP connection issue through firewall

i'm confused about TCP connection through firewall.
Source Port(client) is 12345 and dest port(server) is 1433.
At the begining, client successfully sends the request to server from 12345 to 1433. When server sending back, does the client require to open port 12345 in Firewall?
If yes, it's hard to configure all ports since source port is dynamic.
Best Regards,
Tom
When server sending back, does the client require to open port 12345 in Firewall?
No. If the client's firewall permitted the outbound connection, it will permit the return traffic.
If yes, it's hard to configure all ports since source port is dynamic.
Impossible, actually.
Of course there are always ways to mis-configure firewalls ...

Is OpenShift's socket accessible from outside?

I need a socket connection, to receive byte streams, for my app that needs to be accessed from outside. Port Forwarding only redirects HTTP traffics and binding to $OPENSHIFT_PYTHON_IP does not make it publicly available. Is there any workaround?
There is not currently a way to open a raw tcp socket to your gear on OpenShift through it's public ip. You would have to open a port between 15,000 and 20,000 and then use rhc port forward command to access it.

Connectivity issues with SSL Socket Server

Socket Server with SSLStream some times refuses new connections from clients.
I used the telent hostname port, and it says Connecting To host...
Could not open connection to the host, on port 6002: Connect failed
I used netstat -a , and I see TCP status as
TCP 0.0.0.0:6002 host:0 LISTENING
I also see the service as listening in tcpview too.
The error I see on client side is connection refused with error code 10061.
The same socket server was accepting new connections and just runs fine without any issues.But after some time the above issue happens.its random.
When I restart the sockets it just works fine and accepts conenctions, which I don;t want to do it frequently.becasue this disconnects clients, who are already connected.
Could somebody help me to trouble shoot this?
Thanks.
Where are you running netstat? On the server?
Try connecting to the socket from localhost (from the server itself) using the destination IP address 127.0.0.1
Do the same test with the network IP of the server.
My guess is that the firewall is preventing external access or a router in between is preventing the connection.
It works for a while and then stops. Few options I can think of:
Some firewall on the way does some kind of throttling
You open and close too many connections too quickly. In this case you exhaust the ephemeral ports on the client (usually) and/or on the server. If you do netstat -a you will see a lot of sockets in TIME_WAIT state, try this both on client and server. Solution here is to reuse connections (best). Or increase the number of ephemeral ports (registry setting). But this will take you only so far.
You have a bug in your server and it stops accepting new connections after a while.

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.