I have a very simple C# client/server chat application with TCP/IP Protocol that it works on local network but I want to use it on internet network but it seem is not easily in C# and I must to do port forwarding on server router or use SSH Tunnel but I do not know How to do them?
Please help me by show me an example, a resource or a code that works....
Thank you.
What I have tried:
I just have a very simple C# client/server chat application with TCP/IP Protocol that it works on local network but I want to use it on internet network:
Server side Program:
namespace TCPIPDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SimpleTcpServer server;
private void Form1_Load(object sender, EventArgs e)
{
server = new SimpleTcpServer();
server.Delimiter = 0x13;
server.StringEncoder = Encoding.UTF8;
server.DataReceived += Server_DataReceived;
}
private void Server_DataReceived(object sender, SimpleTCP.Message e)
{
txtStatus.Invoke((MethodInvoker)delegate ()
{
txtStatus.Text += e.MessageString;
e.ReplyLine(string.Format("You said: {0}", e.MessageString));
});
}
private void btnStart_Click(object sender, EventArgs e)
{
txtStatus.Text += "Server starting...";
System.Net.IPAddress ip = System.Net.IPAddress.Parse(txtHost.Text);
server.Start(ip, Convert.ToInt32(txtPort.Text));
}
private void btnStop_Click(object sender, EventArgs e)
{
if (server.IsStarted)
server.Stop();
}
}
}
Client side Program:
namespace Client
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
SimpleTcpClient client;
private void btnConnect_Click(object sender, EventArgs e)
{
btnConnect.Enabled = false;
client.Connect(txtHost.Text, Convert.ToInt32(txtPort.Text));
}
private void Form1_Load(object sender, EventArgs e)
{
client = new SimpleTcpClient();
client.StringEncoder = Encoding.UTF8;
client.DataReceived += Client_DataReceived;
}
private void Client_DataReceived(object sender, SimpleTCP.Message e)
{
txtStatus.Invoke((MethodInvoker)delegate ()
{
txtStatus.Text += e.MessageString;
});
}
private void btnSend_Click(object sender, EventArgs e)
{
client.WriteLineAndGetReply(txtMessage.Text, TimeSpan.FromSeconds(3));
}
}
}