So I'm fairly new to programming and decided to try some networking but I'm stuck. I tried to create a simple client and server just to establish a connection. Obviously, it doesnt work, and I've looked around but can't find any new information to help me. So I decided to try here.
Here is what's happening when I run the client and server:
(I'm running the client and server on the same computer)
*Client connects to server (localhost):
-System.Exception: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
*Client connects to server when server is not running:
-System.Exception: No connection could be made because the target machine actively refused it.
*Client connects to localhost at port 80 (which is not the server):
-Connection established
*Client connect to HostName google.com at port 80:
-Connection established
*Client connects to random ip and port:
-System.Exception: No such host is known.
Servercode:
public sealed partial class MainPage : Page
{
StreamSocketListener _listener = new StreamSocketListener();
string port = "1800";
public MainPage()
{
this.InitializeComponent();
listener();
}
private async void listener()
{
_listener.ConnectionReceived += listenerConnectionReceived;
await _listener.BindServiceNameAsync(port);
}
void listenerConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
{
tb_server.Text = "Connection received.";
}
private void btn1_Click(object sender, RoutedEventArgs e)
{
}
}
Clientcode:
public sealed partial class MainPage : Page
{
StreamSocketListener _listener = new StreamSocketListener();
string port = "1800";
public MainPage()
{
this.InitializeComponent();
listener();
}
private async void listener()
{
_listener.ConnectionReceived += listenerConnectionReceived;
await _listener.BindServiceNameAsync(port);
}
void listenerConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
{
tb_server.Text = "Connection received.";
}
private void btn1_Click(object sender, RoutedEventArgs e)
{
}
}