How to host a TcpClient/listener online (I want to host my chat server online) - tcp

I have a chat server that i create for my window phone app. Right now it working on my local computer, how do i make it online so everyone can connect to it.
Chat server:
TcpListener chatServer = new TcpListener(4296);
Chat client:
TcpClient client = new TcpClient("127.0.0.1", 4296);
How do i forward the port so i can host it online!

In order for the world to see it you need to host it somewhere with a public IP address. You will then use this IP address in the client connection:
Chat client: TcpClient client = new TcpClient("xxx.xxx.xxx.xxx", 4296);
Depending on your platform you could use Google App Engine or Amazon Web Services to quickly deploy your application.

That depends on your router/gateway. Check your router's documentation for more information how to forward ports.

Basically If you want to deploy your app online you need your own Domain(you get your own IP to host), you can use Cloud Server to deploy(these is a good option, since you can deploy for free but storage is limited in free edition), Or else you can Host on your Routers IP Address.
If you are using first two option then these is a python script to start a listener service on given IP and port.
Here:
import socket
import sys
HOST ='' # Symbolic name, meaning all available interfaces
PORT = 8000 # Arbitrary non-privileged port
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'
try:
s.bind((HOST, PORT))
except socket.error as msg:
print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
sys.exit()
print 'Socket bind complete'
#Start listening on socket
s.listen(10)
print 'Socket now listening'
#now keep talking with the client
while 1:
#wait to accept a connection - blocking call
conn, addr = s.accept()
print 'Connected with ' + addr[0] + ':' + str(addr[1])
s.close()
These is just a sample, you can put all of Your code from Your PC to Cloud and edit the changes in IP.
And if you want your router to listen to the client then you have to go to the routers login page, for most of the router it is 192.168.51.1, go here and login as administrator, Then you should go to firewall configuration over there you will find an option of custom server, then click on it and then there configure the ip address, port,etc to host.
I prefer you to watch these full video to understand properly: Here Video
In these video he is hosting for exploitation purpose you can host to do any other activity.
Thank You.

Related

Shadowsocks client cannot connect my Shadowsocks server

I am trying to set up a Shadow Socks connection from China. To do that, I
downloaded and installed a ShadowCocks client (ShadowsocksX-NG.app) on my local, and configure
create a ShadowCocks service at a server aboard
For 2), I have created one instance on AWS of east US zone, and the service is already started with the following configuration. The server instance is SECURED with key pair for connection.
{
"server":"0.0.0.0",
"local_address":"127.0.0.1",
"local_port":1080,
"port_password":{
"7777":"password1",
"8888":"password2"
},
"timeout":300,
"method":"aes-256-cfb",
"fast_open":false
}
For 1), I connect with the address of the server instance's address, port number 7777 and password = password1.
I use global mode (to ensure Shadowcocks kick in) for ShadowCocks client and start it, no website gets loaded (both blocked sites and unblocked sites by the GFW). I assert there is problem with the connection between the Shadowcocks client side and server sides). I also tried different encyption algorithm but still doesn't load.
I need some hint on where the problems might be!
I suspect something wrong with the crytographics? I think the concept of Shadowcocks is that
the client side encrypts the URL and sends it to the server side
then the server side receives the encrypted text and decrypt it, and then fetch the result with the decrypted URL.
I am guessing the problem might occur at this part. I don't see how my client side encrypts or how my server side can decrypt since I didn't share the keys between the 2 sides.
Set the inbound rules to allow traffics to port 7777 and 8888.
type = TCP
port = 7777 or 8888
source = 0.0.0.0/0
So Shadowsocks will be able to connect.

Openvpn gateway, redirect only remote local traffic

I currently have an OpenVPN server (install on Raspbian, in gateway mode), which, when connecting, passes all Internet traffic through it. I want only the resource requests contained on the remote local network to be shared.
This would give:
User --> request to Remote File Server --> VPN (10.0. *. *)
User --> other request --> Local gateway
Thanks for your help.
This is something you can change in your client (.ovpn) configuration. If you export your user profile to an ovpn file:
ovpn_getclient username > username.ovpn
Edit this username.ovpn file and comment out this section:
redirect-gateway def1 -> #redirect-gateway def1
Change device mode to "tap - Layer 2 mode" in server settings, This will connect the client part of the remote network but internet traffic will pass through the local gateway. to pass through the traffic for the selected client add "route-delay 15" in the server config. and add "push “route-delay 15” " in the client advanced config section.

Google Cloud Platform: VPC Connector Not Working with Cloud Function

We're developing a web server with Firebase that will have to talk to various PLCs behind customer firewalls. I have a couple PLCs on my local network that I'm working with. I'm just trying to do a basic ping right now. I installed the ping module and am trying to run this node.js code:
function pingTest(){
const ping = require('ping');
const hosts = [
'10.10.100.11',
'10.10.100.119',
'10.10.100.12',
'10.10.100.118',
];
hosts.forEach(function(host){
ping.sys.probe(host, function(isAlive){
var msg = isAlive ? 'host ' + host + ' is alive' : 'host ' + host + ' is dead';
console.log(msg);
});
});
}
I've setup a VPN gateway and tunnel on GCP. The tunnel status is "Established". I have a Serverless VPC Access Connector setup as well. Everything is using the "us-central1" region. The connector is assigned to my cloud function for all traffic.
Running locally, I can ping the .11 and .12 PLCs just fine. When running in Firebase though, all four hosts report "dead".
When looking at the GCP Logs Viewer, I'm not seeing any error codes. The logs for my function are only what I'm writing to the console:
10:06:00.180 AM every1MinuteBackgroundPlcRead Function execution started
10:06:02.693 AM every1MinuteBackgroundPlcRead host 10.10.100.11 is dead
10:06:03.793 AM every1MinuteBackgroundPlcRead host 10.10.100.12 is dead
10:06:03.794 AM every1MinuteBackgroundPlcRead host 10.10.100.119 is dead
10:06:04.393 AM every1MinuteBackgroundPlcRead host 10.10.100.118 is dead
10:07:00.206 AM every1MinuteBackgroundPlcRead Function execution took 306 ms, finished with status: 'ok'
I'm not even seeing an option for VPC connector logging. I see the option for the tunnel logs; but there're empty. The logs for the gateway are just these lines repeated over and over:
2020-02-24T15:00:27.885866755Z sending DPD request
2020-02-24T15:00:27.886004404Z generating INFORMATIONAL request 95 [ ]
2020-02-24T15:00:27.886142741Z sending packet: from 34.66.113.10[500] to 50.205.87.130[500] (49 bytes)
2020-02-24T15:00:27.911746950Z received packet: from 50.205.87.130[500] to 34.66.113.10[500] (49 bytes)
2020-02-24T15:00:27.911828853Z parsed INFORMATIONAL response 95 [ ]
It doesn't seem like my code is utilizing the VPC connector that I assigned to the function. I assume I'm missing a critical link in my chain? Any help? Thanks!

JavaDB(Derby) - Connection refused using Network Server Controller in LAN

I'm new to java networking. My scenario here is 2 client computers are connecting to a server hosted in LAN. So I use NetworkServerControl API to start the host:
private static void startServer(){
try{
NetworkServerControl nsc = new NetworkServerControl(InetAddress.getByName("localhost"), 1527);
nsc.start(null);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Start network error : " + e.getMessage());
}
My questions are:
1) Is localhost accessible by computers in LAN?
- If yes, I tried to use ij to connect derby database in the server but it wrote connection refused. Anything I missed out?
ij: CONNECT 'jdbc:derby://localhost:1527/c:/app_db/' user 'xxx' password 'xxx';
- If no, what is the common approach should be used? Please guide me the right track.
Thanks.
To access your Derby database from other machines on the network, you need to change "localhost" to a different value. You can give the DNS name of your machine, or the public IP address of your machine.
Note that you have to make this change both on the Derby server and on each of the client URLs.
You should be able to use netstat -a to confirm the effects of your changes on the server.

C# Detect Localhost Port Usage

In advance, thank you for your advice.
I am currently working on a program which uses Putty to create a SSH connection with a server that uses local port forwarding to enable a client, running my software, to access the service behind the SSH server via localhost.
IE: client:20100 -> Internet -> Remote SSH server exposed via router/firewall -> Local Intranet -> Intranet Web POP3 Server:110.
Cmd Line: "putty -ssh -2 -P 22 -C -L 20100:intranteIP:110 -pw sshpassword sshusername#sshserver"
Client would use putty to create a SSH connection with the SSH server specifying in the connection string that it would like to tie port 110 of the Intranet POP3 Server to port 20100 on the client system. Therefore the client would be able to open up a mail client to localhost:20100 and interact with the Internal POP3 server over the SSH tunnel. The above is a general description. I already know what I am trying to do will work without a problem so am not looking for debate on the above.
The question is this...How can I ensure the local port (I cannot use dynamic ports, so it must be static) on localhost is not being used or listened to by any other application?
I am currently executing this code in my C# app:
private bool checkPort(int port)
{
try
{
//Create a socket on the current IPv4 address
Socket TestSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Create an IP end point
IPEndPoint localIP = new IPEndPoint(IPAddress.Parse("127.0.0.1"), port);
// Bind that port
TestSocket.Bind(localIP);
// Cleanup
TestSocket.Close();
return false;
}
catch (Exception e)
{
// Exception occurred. Port is already bound.
return true;
}
}
I am currently calling this function starting with a specific port in a for loop to get the 'false' return at the first available port. The first port I try is actually being listened to by uTorrent. The above code does not catch this and my connection fails.
What is the best method to ensure a port is truly free? I do understand some other program may grab the port during/after I have tested it. I just need to find something that will ensure it is not currently in use AT ALL when the test is executed.
If there is a way to truly reserve the localhost port during the test, I would love to hear about it.
Here's the answer how to check if local port is free.
I would recommend this way:
bool IsBusy(int port)
{
IPGlobalProperties ipGP = IPGlobalProperties.GetIPGlobalProperties();
IPEndPoint[] endpoints = ipGP.GetActiveTcpListeners();
if ( endpoints == null || endpoints.Length == 0 ) return false;
for(int i = 0; i < endpoints.Length; i++)
if ( endpoints[i].Port == port )
return true;
return false;
}

Resources