PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label port. Show all posts
Showing posts with label port. Show all posts

Saturday, October 22, 2022

[FIXED] How many tuples are there in a connection?

 October 22, 2022     ip, port, protocols, sockets, tuples     No comments   

Issue

Some people said that there are 4 tuples in a connection

client IP address, client port number, server IP address, server port number

Some said that there are 5

client IP address, client port number, server IP address, server port number, protocol

Which one is correct ?


Solution

You've misunderstood the terminology. A TCP connection is identified by a 5-tuple. That means one tuple, with 5 elements. The five elements are:

  1. Protocol. This is often omitted as it is understood that we are talking about TCP, which leaves 4.
  2. Source IP address.
  3. Source port.
  4. Target IP address.
  5. Target port.


Answered By - user207421
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] how to do something like streams inside a port (Python socket)

 October 22, 2022     multithreading, port, python, sockets, tcp     No comments   

Issue

there is such a code:

server:

import socket
from threading import Thread
from time import sleep

sock = socket.socket()

sock.bind(('', 1337))
sock.listen(1)
conn, addr = sock.accept()
def func1():
    while True:
        conn.send("1".encode("utf-8"))
        sleep(0.5)
def func2():
    while True:
        conn.send("2".encode("utf-8"))
        sleep(0.5)
t1 = Thread(target=func1)
t1.start()
t2 = Thread(target=func2)
t2.start()

client:

import socket
from threading import Thread
from time import sleep

sock = socket.socket()
sock.connect(('localhost', 1337))

def func1():
    while True:
        data = sock.recv(1024).decode("utf-8")
        if data != "1":
            print("the package did not arrive properly")
        else:
            print("package arrived ok")
def func2():
    while True:
        data = sock.recv(1024).decode("utf-8")
        if data != "2":
            print("the package did not arrive properly")
        else:
            print("package arrived ok")
t1 = Thread(target=func1)
t1.start()
t2 = Thread(target=func2)
t2.start()

I need to make sure that the packet sent by function1 comes to function1, and the packet of function2 comes to function2, but this code does not work correctly, and packets from function1 often end up in function2 and vice versa


Solution

I feel like you are approaching this from the wrong direction. You do not need multiple threads in the server or client. If you have multiple threads that is fine, but that's really not relevant for the problem you are having.

You are trying to multiplex multiple different types of messages over a single socket connections. In other words, you need a communication protocol.

On top of that, you have another problem that you do not appear to be aware of yet. Sockets are streams of bytes, in particular, they are not messages. If you send multiple messages in quick succession, they might be truncated or combined in the receiver.

If you send the following packages:

1
2
1
1
2

They could be received as follows:

12
112

Then your receiver will be very confused. Again, this problem can be resolved with a communication protocol.


There are many different ways to implement a communication protocol. The simplest that I can think of is to use JSON:

# sender.py

import socket
import time
import json

sock = socket.socket()

# https://stackoverflow.com/a/6380198/8746648
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)

sock.bind(('', 1337))
sock.listen(1)
conn, addr = sock.accept()

while True:
    # If necessary, you can make these calls from different threads.
    # Notice, that we append a newline at the end, this is needed for 'readline' to work properly.
    conn.send(json.dumps({ "type": 1, "payload": 42 }).encode("utf-8") + b"\n")
    time.sleep(0.5)
    conn.send(json.dumps({ "type": 2, "payload": "can-be-anything" }).encode("utf-8") + b"\n")
    time.sleep(0.5)
# receiver.py

import socket
import json

sock = socket.socket()
sock.connect(('localhost', 1337))

# We know, that the messages themselves do not contain newline characters
# and the server sends a newline after each message, therefore, this will receive a complete message.
sock_file = sock.makefile()
while line := sock_file.readline():
    object_ = json.loads(line)

    # If you want to you can handle the messages in different threads.
    # This could be done by setting up a queue that is consumed by working threads.
    if object_["type"] == 1:
        print(f"received(1): {object}")
    elif object_["type"] == 2:
        print(f"received(2): {object}")


Answered By - asynts
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why is this port still open after I killed the process which occupied this port?

 October 22, 2022     cmd, networking, port, sockets, tcp     No comments   

Issue

I typed this command in Windows cmd:

netstat -nao | findstr 9300

The output is:

  TCP    0.0.0.0:9300           0.0.0.0:0              LISTENING       6676
  TCP    10.206.90.163:59300    180.181.184.37:443     ESTABLISHED     1960
  TCP    127.0.0.1:9300         127.0.0.1:5907         ESTABLISHED     6676
  TCP    127.0.0.1:9300         127.0.0.1:5908         TIME_WAIT       0
  TCP    127.0.0.1:9300         127.0.0.1:5908         ESTABLISHED     6676
  TCP    127.0.0.1:9300         127.0.0.1:5909         TIME_WAIT       0
  TCP    127.0.0.1:9300         127.0.0.1:5913         TIME_WAIT       0
  TCP    127.0.0.1:9300         127.0.0.1:5914         TIME_WAIT       0
  TCP    127.0.0.1:9300         127.0.0.1:5914         ESTABLISHED     6676
  TCP    127.0.0.1:9300         127.0.0.1:5914         TIME_WAIT       0
  TCP    127.0.0.1:9300         127.0.0.1:5915         ESTABLISHED     6676
  TCP    127.0.0.1:9300         127.0.0.1:5917         TIME_WAIT       0
  TCP    127.0.0.1:9300         127.0.0.1:5917         TIME_WAIT       0
  TCP    127.0.0.1:9300         127.0.0.1:5917         TIME_WAIT       0
  TCP    127.0.0.1:9300         127.0.0.1:5917         TIME_WAIT       0
  TCP    127.0.0.1:9300         127.0.0.1:5918         TIME_WAIT       0

Then I found that port 9300 was occupied by the process whose PID is 6676. Then I checked the process's name by typing, and killed this process:

tasklist | findstr 6676

After I killed this, I typed the following command to check which port is still open.

netstat -a

The output is:

TCP    0.0.0.0:9300           DESKTOP-7AI5AKV:0      LISTENING

How could this be possible? I just closed this port. How could this still be listening?


Solution

A service in listening mode on all ports will show in netstat as this:

0.0.0.0:9300

You can locate which process is listening to this port with this command:

% lsof | grep LISTEN
sshd        511                           root    3u     IPv4              12453      0t0        TCP *:ssh (LISTEN)

For example, my sshd is currently pid = 511.

Killing the server PID will have the server restarted by the init system (e.g. systemd on Linux or launch services on macOS). You can encourage the server to restart by doing kill -15 511 for PID 511. You can also try -9 if it does not restart.

The ESTABLISHED and TIME_WAIT are active connections and closed pending 2 minute expire timer clearing.



Answered By - James Risner
Answer Checked By - Timothy Miller (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How can I detect what program is listening to a TCP/IP port in Windows?

 October 22, 2022     ip, port, sockets, tcp, vb6     No comments   

Issue

I have an application that I inherited that listens on port 7001 for UDP broadcasts from our in-house test equipment, and I recently updated another application that needs to do the same thing. Both applications must be able to coexist on the same computer.

Currently, when my recently updated application attempts to bind to the port to listen for UDP broadcasts and fails, it simply reports that the port is not available and suggests that the inherited application is probably running. How can I get my application to detect what application is actually listening on that port? I've done a Google search and have even searched this site, but so far I have been unable to find anything except to use Task Manager, TCPView, or netstat at the command line.

I would prefer a technique that either uses the Windows API or a Windows system COM component, since both applications are written in Visual Basic 6.0. (I know, I know, but I must maintain these applications since they are mission critical.) However, a .NET solution would would also be useful in case I need it in my new development efforts.


Solution

Use:

netstat -n -o

That will show the process ID and from there you can either look in the Task Manager's process viewer, go to menu View → Columns... and check the Process ID (PID). Then you can see the name of the process listening on that port.

Of course, you're wanting a programmatic way of accomplishing this and the GetTCPTable2 API is best as was already suggested. In fact, if you look at the IAT (Import Address Table) for netstat.exe, it actually uses that API to get that information.

There is a way to communicate directly with a command window and get its output using pipes and it would work fine, but the ideal way is to simply use the same API netstat uses.



Answered By - Daniel W. Elkins
Answer Checked By - Pedro (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, September 6, 2022

[FIXED] Why is Heroku site not working with my app name? [Application Error]

 September 06, 2022     git-bash, heroku, port, python, web-deployment     No comments   

Issue

I have pushed files from my computer to heroku using git which bundles the app to publish on the web during a Udacity course.

When I use https://git.heroku.com/mmishal001.git as per my git bash output - it gives me Method not allowed

On doing research there was a stack answer to use https://mmishal001.herokuapp.com/ but its giving me an Application Error

How can I successfully view my site?

Here are the logs:

2020-05-22T21:08:45.108618+00:00 app[api]: Initial release by user mohammedmishal@live.com
2020-05-22T21:08:45.108618+00:00 app[api]: Release v1 created by user mohammedmishal@live.com
2020-05-22T21:08:45.278750+00:00 app[api]: Release v2 created by user mohammedmishal@live.com
2020-05-22T21:08:45.278750+00:00 app[api]: Enable Logplex by user mohammedmishal@live.com
2020-05-22T21:52:19.000000+00:00 app[api]: Build started by user mohammedmishal@live.com
2020-05-22T21:52:46.729204+00:00 app[api]: Deploy 04bcf12c by user mohammedmishal@live.com
2020-05-22T21:52:46.729204+00:00 app[api]: Release v3 created by user mohammedmishal@live.com
2020-05-22T21:52:46.751622+00:00 app[api]: Scaled to web@1:Free by user mohammedmishal@live.com
2020-05-22T21:52:50.870397+00:00 heroku[web.1]: Starting process with command `python BookmarkServer.py`
2020-05-22T21:52:55.000000+00:00 app[api]: Build succeeded
2020-05-22T21:53:51.264392+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-05-22T21:53:51.314513+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-05-22T21:53:51.498696+00:00 heroku[web.1]: Process exited with status 137
2020-05-22T21:53:51.545336+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-22T21:53:51.547570+00:00 heroku[web.1]: State changed from crashed to starting
2020-05-22T21:53:54.506792+00:00 heroku[web.1]: Starting process with command `python BookmarkServer.py`
2020-05-22T21:54:54.727943+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-05-22T21:54:54.749643+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-05-22T21:54:54.863009+00:00 heroku[web.1]: Process exited with status 137
2020-05-22T21:54:54.904317+00:00 heroku[web.1]: State changed from starting to crashed
2020-05-22T21:59:33.545036+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=mmishal001.herokuapp.com request_id=4587c886-5ab7-4677-aa98-51b0bdd23c6d fwd="92.98.87.71" dyno= connect= service= status=503 bytes= protocol=https
2020-05-22T21:59:34.335527+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=mmishal001.herokuapp.com request_id=416ec5ae-4cf5-4aee-b4d6-16c0346c9aa6 fwd="92.98.87.71" dyno= connect= service= status=503 bytes= protocol=https
2020-05-22T22:00:48.204841+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=mmishal001.herokuapp.com request_id=b4721bbe-2a11-4a24-abde-28c7e44436aa fwd="92.98.87.71" dyno= connect= service= status=503 bytes= protocol=https
2020-05-22T22:00:49.025113+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=mmishal001.herokuapp.com request_id=c8039bf7-ae5c-4aa0-9dd9-d2a4a1100e13 fwd="92.98.87.71" dyno= connect= service= status=503 bytes= protocol=https
2020-05-22T22:02:33.399278+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=mmishal001.herokuapp.com request_id=a3dd26f4-8267-4576-b86b-bf44fe0fef18 fwd="92.98.87.71" dyno= connect= service= status=503 bytes= protocol=https
2020-05-22T22:02:33.908128+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=mmishal001.herokuapp.com request_id=0f31c73b-beec-4d38-b8f1-b055fbae76a0 fwd="92.98.87.71" dyno= connect= service= status=503 bytes= protocol=https

This is the port info from the .py file, .py file


Solution

Heroku automatically assigns your heroku app a port, so when you can't set the port to a fixed number. Heroku adds the port to the env, so you can pull it from there. Switch your listen to this:

.listen(process.env.PORT || 5000)

That way it'll still listen to port 5000 when you test locally, but it will also work on Heroku.

Let me know if this answer helped you

check this answer https://stackoverflow.com/a/15693371/6392696



Answered By - nourza
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, August 1, 2022

[FIXED] How to setup PHP server in production?

 August 01, 2022     php, port, ssh, vps, webserver     No comments   

Issue

I use php -S 127.0.0.1:4242 command to start development server on localhost for php files. But I guess, I shouldn't use this thing in production. Currently I'm trying to setup my website on VPS and I don't know how to start php server forever using ssh on port 4242. I know, this is probably very dumb question, this is my first time I work with real hosting

Would be grateful to any help :)


Solution

You need to setup virtual host so that it should run always.

Here is a full doc of setup guide on server.



Answered By - dev_mustafa
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Sunday, July 3, 2022

[FIXED] How to set xampp open localhost:8080 instead of just localhost

 July 03, 2022     apache, localhost, port, xampp     No comments   

Issue

I use XAMPP 1.7.3. Apache and MySQL installed. Nothing else.

Apache installed on default port 80. Clicking on Admin next to Apache opens http://localhost/xampp/. Which works as expected.

I navigated to xampp/apache/conf/httpd.conf and edited it. Set Listen 8080. Now http://localhost:8080/xampp/ works as expected but the Admin button still opens http://localhost/xampp/ which does not open anything. I have restarted the computer after doing so with no results.

How to make XAMPP apache admin open localhost:8080/xampp ?


Solution

I believe the admin button will open the default configuration always. It simply contains a link to localhost/xampp and it doesn't read the server configuration.

If you change the default settings, you know what you changed and you can enter the URL directly in the browser.



Answered By - Stelian Matei
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Friday, June 24, 2022

[FIXED] How to setup local domain in local network that everyone can see?

 June 24, 2022     dns, networking, port, proxy, reverse-proxy     No comments   

Issue

I have a few web-based local applications for home-automation purposes, those are accessible through IP addresses with port numbers something like http://192.168.1.100:8080.

What I am trying to achieve is to link each individual IP and port number combination to an internal domain name, so that anyone can use domain and subdomain names rather than IP addresses.

For example a person can specify a URL of http://kitchen.home rather than an IP address with port number URL such as http://192.168.1.100:8080.

At the same time http://192.168.1.100:8081 could be mapped to a domain name such as hall.home so that a URL of http://hall.home could be used instead of that IP address and port number.

The access to a server should not require having to modify the hosts file of individual PCs but should be some kind of a domain name server that maps domain names to IP address and port number for any PC on the local network.


Solution

I have set up a DNS server on a PC running bind9 as a DNS server under Ubuntu 20.04 on my home network in order to have my own special domain names.

A few details about DNS and proxy server with HTTP

To map several different subdomain names within a domain to specific ports on the same PC, you will need a proxy server installed on the the PC as well as a DNS server for the local network. Domain names are mapped to a specific IP address with the DNS protocol and are not mapped to a specific port at the IP address.

In my case I have the same PC hardware with Ubuntu 20.04 that has (1) Bind9 for my DNS server and (2) Apache for my proxy server. I could use two different PCs, one as a DNS server to resolve domain names to IP addresses and the other offering various services accessed either through a single IP port using a proxy server listening on the port to dispatch connections to the services or directly to the service by specifying the correct port number of the desired service.

For example http://kitchen.home/ in a browser would instruct the browser to open a TCP connection to the IP address represented by the domain name kitchen.home using port 80, the default HTTP protocol port. A DNS server is used to resolve the domain name kitchen.home to an IP address. With a URL of http://kitchen.home:8081/, the browser will ask the DNS server to resolve the domain name kitchen.home to an IP address and then open a TCP connection to that IP address but using port 8081 rather than the standard HTTP port 80.

So for http://kitchen.home/ to map to port 8080 at that IP address and for http://hall.home/ to map to port 8081 at that IP address you need to combine a DNS server, which resolves the domain name, with a proxy server residing at port 80, the standard HTTP port. The proxy server will then redirect the request to a different port on the PC selected based on the subdomain name, hall or kitchen, of the entire domain specifier, kitchen.home or hall.home.

See https://stackoverflow.com/a/58122704/1466970 which describes setting up Nginx as a proxy server.

The Apache web server can also serve as a proxy server which is what I'm looking into. See this tutorial from DigitalOcean, How To Use Apache HTTP Server As Reverse-Proxy Using mod_proxy Extension as well as Setting up a basic web proxy in apache.

My environment

I have a Windows 10 PC downstairs with a Ubuntu 20.04 PC upstairs communicating through an Arris router to my cable internet provider. Both PCs are connected to my local home network with WiFi.

The Ubuntu 20.04 PC is my Subversion server using Apache web server. I spend most of my time with the Windows 10 PC downstairs, using PuTTY to connect to the Ubuntu PC with one or more terminal windows when needed. I plan to work with Visual Studio on the Windows 10 PC accessing Subversion through the Apache web server as well as using the Ubuntu PC as a database server (MySQL) and web server (Apache with Php) and microservices (golang and node.js).

I wanted to setup a DNS server on the Ubuntu PC and then point my Windows 10 PC to use the local DNS server for a special domain name while using standard DNS servers such as Google at 8.8.8.8 and 8.8.4.4.

What I did

The procedure I followed was (see How to Configure BIND9 DNS Server on Ubuntu 20.04 and see as well Domain Name Service (DNS) and Everything You Need To Know About Ubuntu DNS Servers):

  • install bind9 using sudo apt install bind9
  • create a firewall rule sudo ufw allow Bind9
  • modify the file /etc/bind/named.conf.options
  • modify the file /etc/bind/named.conf.local
  • create a copy of /etc/bind/db.local for my new domain name, home.x
  • modify the new file, /etc/bind/db.home.x, with the correct rules

The domain name I wanted to use locally was home.x with the idea that if I entered a web site URL of http://www.home.x/ the resulting page would be the Apache web server on my Ubuntu PC. Or if I entered http://home.x/svn the result would be the Subversion repository on my Ubuntu server.

Note: in order for Subversion access through Apache, I had to set that up. See enabling Subversion access via Apache web server and DAV on Ubuntu if you are interested in that.

Details on changes and modified files

The Ubuntu PC has an IP address of 192.168.0.4 on my local network. In the descriptions below, this IP address is used where ever the Ubuntu PC is referenced.

I added a forwarders section to the file /etc/bind/named.conf.options in order to forward any DNS requests that were unknown to my Ubuntu server to some other DNS server. The IP addresses I copied from the list of DNS servers returned by the Window 10 command ipconfig /all which I ran on my Windows 10 PC. The changed file is as follows:

rick@rick-MS-7B98:~/Documents$ cat /etc/bind/named.conf.options
options {
        directory "/var/cache/bind";

        // If there is a firewall between you and nameservers you want
        // to talk to, you may need to fix the firewall to allow multiple
        // ports to talk.  See http://www.kb.cert.org/vuls/id/800113

        // If your ISP provided one or more IP addresses for stable
        // nameservers, you probably want to use them as forwarders.
        // Uncomment the following block, and insert the addresses replacing
        // the all-0's placeholder.

        // forwarders {
        //      0.0.0.0;
        // };

        // following forwards are to Google DNS servers at 8.8.8.8 and 8.8.4.4
        forwarders {
                8.8.8.8;
                8.8.4.4;
                209.55.27.13;
        };

        //========================================================================
        // If BIND logs error messages about the root key being expired,
        // you will need to update your keys.  See https://www.isc.org/bind-keys
        //========================================================================
        dnssec-validation auto;

        listen-on-v6 { any; };
};

After changing the file /etc/bind/named.conf.options, I then ran the check utility, which found no errors, and then restarted the bind service.

sudo named-checkconf
sudo systemctl restart bind9

Next I added a new zone directive to the file /etc/bind/named.conf.local to create a DNS entry for my new, local domain name home.x. The modified file looks like:

rick@rick-MS-7B98:~/Documents$ cat /etc/bind/named.conf.local
//
// Do any local configuration here
//

// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";

zone "home.x" {
        type master;
        file "/etc/bind/db.home.x";
};

Finally I needed to create the file /etc/bind/db.home.x specified in the file directive of the zone directive. I did this by starting with a copy of the existing file /etc/bind/db.local by using the command

sudo cp /etc/bind/db.local /etc/bind/db.home.x

I then modified the file /etc/bind/db.home.x in order to specify the rules I needed to resolve the domain name of home.x as well as the subdomain of www.home.x to the IP address of my Ubuntu PC. The modified file looks like:

rick@rick-MS-7B98:~/Documents$ cat /etc/bind/db.home.x
;
; BIND data file for local loopback interface
;
$TTL    604800
@       IN      SOA     home.x. root.home.x. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      ns.home.x.
@       IN      A       192.168.0.4
@       IN      AAAA    ::1
ns      IN      A       192.168.0.4
www     IN      A       192.168.0.4

At this point I could test that things worked from my Windows 10 PC by using the nslookup command from a command window. I tried it first without specifying the Ubuntu PC IP address and then with the Ubuntu PC IP address

C:\Users\rickc>nslookup home.x
Server:  dns.google
Address:  8.8.8.8

*** dns.google can't find home.x: Non-existent domain

C:\Users\rickc>nslookup home.x 192.168.0.4
Server:  UnKnown
Address:  192.168.0.4

Name:    home.x
Addresses:  ::1
          192.168.0.4

I then used the Windows 10 Control Panel (Control Panel > Network and Internet > Network Connections) to see a list of my network adapters in order to modify the DNS server addresses my WiFi adapter was using. This setting is found by doing a right mouse click on the adapter to pop up a floating menu, select Properties to bring up the Properties dialog then select Internet Protocol Version 4 then click the Properties button on the dialog and modify the DNS server address. Below is a screen shot of the dialogs.

screen shot of network adapter Properties and modifying DNS server address

After modifying the DNS server address, I retried the nslookup without specifying a DNS server address and the command finds home.x:

C:\Users\rickc>nslookup home.x
Server:  UnKnown
Address:  192.168.0.4

Name:    home.x
Addresses:  ::1
          192.168.0.4

When I tested a URL of http://www.home.x/ the test page of my Apache web server is displayed. When I tested a URL of http://home.x/svn the web browser showed the directory tree of my Subversion repository. When I access my Subversion repository with http://home.x/svn/trunk/ within the Ankh Subversion plug-in with Visual Studio 2017 it works.

Other thoughts

One issue with this setup is that if my Ubuntu PC is not up and running then the Windows 10 PC will not have a functioning DNS server until either the Ubuntu PC is brought up or the DNS server address is set back to the original setting on the WiFi adapter. Previously, it was set to discover a DNS server. It may be that I can change this back and from a specified DNS server address, the IP address of my Ubuntu PC, and my Windows 10 PC will discover my Ubuntu PC as a DNS server anyway.



Answered By - Richard Chambers
Answer Checked By - Robin (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to successfully run node server with IIS?

 June 24, 2022     iis-10, javascript, node.js, port, reverse-proxy     No comments   

Issue

So I have a web application with ISS-10, running on wwww.mymindmapper.com and listening on port:80. I have two simple pages (login.html & register.html). Here is what it looks like: https://imgur.com/a/gb9KAsj

My main objective is to try and figure out how to create a Node JS server (port: 81) with my webApp on IIS that is on port: 80. Here is my app.js file:

//USE `nodemon scripts/server.js` on Terminal to refresh Node Server on File Save.
//USE 'pm2 start scripts/server.js' on Terminal to start pm2 for IIS ??????????????????

//Import Node JS modules
const express = require("express");
const morgan = require("morgan"); 
const mysql = require("mysql");

//Create a new instance of express()
const app = express();

//GET INFORMATION ABOUT THE SERVER REQUESTS (OS, Browser, time, Internal Errors, Status Codes)
app.use(morgan('short')); //'short', 'combined'

//Require files from folder public     (THIS CONTAINS ALL .html files inc. login.html and register.html)
app.use(express.static('./public'));

//Listen on PORT:80 with a callback function
app.listen(81, ()=>{
    console.log("Server running on port 81");
});

Please note that when i make requests through terminal on Visual Studio Code, everything works as expected. Data can be added/deleted from my database. (I use XAMPP - Apache listens on port:80 and mMySQL listens on port:3306).

I have read somewhere that this can be solved with a Reverse Proxy on IIS. However this doesn't seems to work. Also when the reverse-proxy configuration is made the following error occurs when i refresh the page.

Reverse proxy configuration

enter image description here


Solution

Buddy, there is no need to set up the outbound rules. the above settings you wrote is enough to forward the IIS requests to node server.
enter image description here
In Application Request Routing, enable proxy functionality.
enter image description here
Index.js

var express=require('express');
var app=express();
app.get('/',function(req,res){
    res.send('Hello World');
})
app.listen(3000,function(){
    console.log("Example app listening on port 3000!");
})

My IIS site bindings.
enter image description here
Result.
enter image description here
Adding the Reverse Proxy Rules generates a webconfig file with below content.

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <rewrite>
            <rules>
                <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                    <match url="(.*)" />
                    <action type="Rewrite" url="http://localhost:3000/{R:1}" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
</configuration>

Besides, if you have created a server farm in the server farms, please remove it or add the local IP as the default server. Otherwise, there will be an error that cannot connect to the server.
Feel free to let me know if the problem still exists.



Answered By - Abraham Qian
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Saturday, May 14, 2022

[FIXED] How to kill a process on a port on ubuntu

 May 14, 2022     kill, port, ubuntu     No comments   

Issue

I am trying to kill a process in the command line for a specific port in ubuntu.

If I run this command I get the port:

sudo lsof -t -i:9001

so...now I want to run:

sudo kill 'sudo lsof -t -i:9001'

I get this error message:

ERROR: garbage process ID "lsof -t -i:9001".
Usage:
  kill pid ...              Send SIGTERM to every process listed.
  kill signal pid ...       Send a signal to every process listed.
  kill -s signal pid ...    Send a signal to every process listed.
  kill -l                   List all signal names.
  kill -L                   List all signal names in a nice table.
  kill -l signal            Convert between signal numbers and names.

I tried sudo kill 'lsof -t -i:9001' as well


Solution

You want to use backtick, not regular tick:

sudo kill -9 `sudo lsof -t -i:9001`

If that doesn't work, you could also use $() for command interpolation:

sudo kill -9 $(sudo lsof -t -i:9001)


Answered By - zellio
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Thursday, April 21, 2022

[FIXED] How to connect ports to a Bus properly in VHDL?

 April 21, 2022     bus, connection, port, vhdl     No comments   

Issue

i am currently fooling around with some VHDL Code to try out a view things. For my current approach i need to split up a bus into ports. Therefore it would be the prettiest solution to "hard connect" the bus with the ports in the entity declaration. Is this possible?

Or is the only solution to connect them in the architecture and "write" them into each other in there?

This is the snippet i am trying to implement accordingly.

entity test is
  port (
    bus    : out std_ulogic_vector(3 downto 0);
    port3   : out std_ulogic;
    port2   : out std_ulogic;
    port1   : out std_ulogic;
    port0   : out std_ulogic;
  );
end test;

Thank you very much for your help.


Solution

The entity describes the external connectivity. The Architecture describes its internal behaviour. So "hardwiring" in the entity is not possible.

In your example, you would need to connect the ports to the same connects as the "bus" output

Note: bus is a reserved word in VHDL.



Answered By - Tricky
Answer Checked By - Dawn Plyler (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do multiple clients connect simultaneously to one port, say 80, on a server?

 April 21, 2022     client-server, connection, http, port, tcp     No comments   

Issue

I understand the basics of how ports work. However, what I don't get is how multiple clients can simultaneously connect to say port 80. I know each client has a unique (for their machine) port. Does the server reply back from an available port to the client, and simply state the reply came from 80? How does this work?


Solution

First off, a "port" is just a number. All a "connection to a port" really represents is a packet which has that number specified in its "destination port" header field.

Now, there are two answers to your question, one for stateful protocols and one for stateless protocols.

For a stateless protocol (ie UDP), there is no problem because "connections" don't exist - multiple people can send packets to the same port, and their packets will arrive in whatever sequence. Nobody is ever in the "connected" state.

For a stateful protocol (like TCP), a connection is identified by a 4-tuple consisting of source and destination ports and source and destination IP addresses. So, if two different machines connect to the same port on a third machine, there are two distinct connections because the source IPs differ. If the same machine (or two behind NAT or otherwise sharing the same IP address) connects twice to a single remote end, the connections are differentiated by source port (which is generally a random high-numbered port).

Simply, if I connect to the same web server twice from my client, the two connections will have different source ports from my perspective and destination ports from the web server's. So there is no ambiguity, even though both connections have the same source and destination IP addresses.

Ports are a way to multiplex IP addresses so that different applications can listen on the same IP address/protocol pair. Unless an application defines its own higher-level protocol, there is no way to multiplex a port. If two connections using the same protocol simultaneously have identical source and destination IPs and identical source and destination ports, they must be the same connection.



Answered By - Borealid
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How do i check for two connections to a sockets at once in python

 April 21, 2022     connection, port, python, server, web     No comments   

Issue

I'm running a python script that listens for incoming connections to my computer. I'm listening on two ports 9999 and 9998. however when im checking for connections to my first port by using .accept() it then waits until i have a connection to run the code underneath meaning my other port can check for connections.

I want to be able to check for connections simultaneously and run code according to what port has been connected to, this is my current code.

import socket
import subprocess
import os


while 1 > 0:
# Set connection for C_shutdown script on port 9999
    HOST = '192.168.1.46' 
    PORT = 9999
    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    server_socket.bind((HOST, PORT))
    server_socket.listen(10)
    print("Listening for Shutdown connection")

# Set connection for Light_on script on port 9998
    HOST = '192.168.1.46' 
    PORT2 = 9998
    light_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    light_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    light_socket.bind((HOST, PORT2))
    light_socket.listen(10)
    print("Listening for Light Connection")

    l = light_socket.accept()
    print("Light script connected")


    s = server_socket.accept()
    print("Shutdown Script Connected")



Solution

Each server should be running in its separate thread, something like this:

# ... other imports ...
import threading

def server_job():
    # ... Code for server_socket ...
    print("Listening for server connection")
    while True:
        s = server_socket.accept()
        # ... Anything you want to do with s ...

def light_job():
    # ... Code for light_socket ...
    print("Listening for Light Connection")
    while True:
        l = light_socket.accept()
        # ... Anything you want to do with l ...

# Creates Thread instances that will run both server_job and light_job
t_server = threading.Thread(target=server_job)
t_light = threading.Thread(target=light_job)

# Begin their execution
t_server.start()
t_light.start()

# Wait for both threads to finish their execution
t_light.join()
t_server.join()

Here each thread has its while True loop to accept several connections, the binding and listening to a port should happen only once.

Other option would be spawning two processes instead of two threads, but that depends on your use case, for example if you don't require to share data between those threads and want a workaround for GIL. In that case, might want to take a look at https://docs.python.org/3/library/multiprocessing.html



Answered By - cmt
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, April 20, 2022

[FIXED] How TCP connections are distinguished during backend service communication?

 April 20, 2022     connection, port, sockets, tcp     No comments   

Issue

Basically I know how browsers are attaching different port to each TCP connection by choosing free ephemeral port and therefore connection is unique, however I don't know how it looks like on TCP level when two backend services connect to each other. Is that similar to how browsers work?

For example let's say I'm sending request from some http client to 'Service A' that is running on 'thread-per-connection' server and listening on port 'X'. Within choosen endpoint I am also sending http request to 'Service B' that listens on port 'Y' (similar service or database), how will it start unique TCP connection between these two services, do 'Service A' acts simlilarly to how browsers handle that?


Solution

The outside HTTP client application is acting as a client to Service A. So that app will use an ephemeral port when making that 1st connection.

Service A then acts as a client to Service B. So Service A will use an ephemeral port when making that 2nd connection.

----------       -------------           -------------
| client | ----> | service A | --------> | service B |
----------       -------------           -------------
         ^       ^           ^           ^
         |       |           |           |
x.x.x.x:e1   y.y.y.y:X   y.y.y.y:e2  z.z.z.z:Y


Answered By - Remy Lebeau
Answer Checked By - Cary Denson (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] Why docker container on specific port return connection refused?

 April 20, 2022     connection, docker, port, vps     No comments   

Issue

I have a Linux VPS with docker installed, I ran an Nginx docker container on a specific port using flag -p, when I try connecting to it using VPS_IP:PORT always get Connection_Refused.

even using curl http://localhost:PORT return connection refused.

Except for port 80, every other port refuses to connect, though ufw is disabled.

docker container command I used:

docker container run -d -it -p 83:83 --name container_name -v /home/.../:/container_path/ nginx

Any thoughts on how to solve this problem?


Solution

Correct docker container command is :

docker container run -d -it -p 83:80 --name container_name -v /home/.../:/container_path/ nginx

Because Nginx docker image is listening on internal port 80



Answered By - Pavel Trzaskalik
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, March 7, 2022

[FIXED] Can't change mamp ports on Mac

 March 07, 2022     macos, mamp, mysql, port, xampp     No comments   

Issue

I recently switched from xampp to mamp because of issues with xampp. I'm trying to change my ports on mamp but when I click Set Web & MySQL ports to 80 & 3306 I get and error reading

There is a problem with the server ports. Each server must be assigned a unique port. Please check your configuration.

I am pretty sure the reason this is doing this is because of my uninstalled xampp. I've searched the web for a solution but can't find anything. Any help would be great, thanks


Solution

The issue was with the nginx port. I set the Nginx port to 81 instead of 80 and it fixed it.



Answered By - Joe Scotto
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing