I wrote two UDP-Sockets. One for client, one for server. As long, as I use them one my local system the server receives the message from the client correctly, But if I try it to setup it on my vps and using the client on my computer, i don't work anymore. I checked incoming connections on my VPS and there aren't any. Could it be that the client can't send the packet to extern network?
Server:
public partial class Network
{
private UdpClient Socket { get; set; }
private IPEndPoint EpFrom = new IPEndPoint(IPAddress.Any, 0);
public void Bind(string address, int port)
{
this.Socket = new UdpClient(new IPEndPoint(IPAddress.Parse(address), port));
Receive();
}
public void Send(string text)
{
byte[] data = Encoding.ASCII.GetBytes(text);
Socket.Send(data, data.Length);
}
private void Receive()
{
Console.WriteLine("Hearing on localhost 11111");
byte[] data = Socket.Receive(ref EpFrom);
Console.WriteLine(Encoding.ASCII.GetString(data));
}
}
Call:
static void Main(string[] args)
{
// Server.Start();
Network server = new Network();
server.Bind("127.0.0.1", 11111);
}
Client:
public class Network
{
private UdpClient Socket { get; set; }
private IPEndPoint EpFrom = new IPEndPoint(IPAddress.Any, 0);
public void Client(string address, int port)
{
this.Socket = new UdpClient(port);
this.Socket.Connect(new IPEndPoint(IPAddress.Parse(address), port));
}
public void Send(string text)
{
byte[] data = Encoding.ASCII.GetBytes(text);
Socket.Send(data, data.Length);
Socket.Close();
}
private void Receive()
{
Console.WriteLine("Hearing on localhost 11111");
byte[] data = Socket.Receive(ref EpFrom);
Console.WriteLine(Encoding.ASCII.GetString(data));
}
}
Call:
static void Main(string[] args)
{
Network client = new Network();
client.Client("144.91.74.110", 8888);
client.Send("test");
}