Mam napisany serwer oraz klient udp w c#. Problem jest w tym, że u mnie wszystko działa, a gdy stawiam serwer na innej maszynie - już nie.
Tutaj kawałek kodu serwera(Serwer wysyła również zapytania do bazy danych, ale wątpię żeby w tym miejscu pojawił się jakiś problem.):
static UdpClient listr;
static void Main(string[] args)
{
string content = "";
SqlConnection connection = null;
string connectionString = "xxx";
connection = new SqlConnection(connectionString);
connection.Open();
listr = new UdpClient(new IPEndPoint(IPAddress.Any, 6769));
while (true)
{
IPEndPoint sender = null;
byte[] data = listr.Receive(ref sender);
string msg = ASCIIEncoding.ASCII.GetString(data);
msg = msg.Remove(0,1);
switch (data[0])
{
case 1:
SqlCommand command = new SqlCommand("SELECT password FROM users WHERE login LIKE '" +
msg.Substring(0, msg.IndexOf(':') ) + "'", connection);
SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
for (int i = 0; i < reader.FieldCount; i++)
{
content += reader.GetValue(i);
}
}
reader.Close();
if (content == msg.Substring(msg.IndexOf(':') + 1,
msg.Length - (msg.IndexOf(':') + 1)))
{
byte[] byt = { 1 };
listr.Send(byt, 1, sender);
}
else
{
byte[] byt = { 0 };
listr.Send(byt, 1, sender);
}
break;
default:
Console.WriteLine(data);
break;
}
content = "";
}
//connection.Dispose();
}
A tutaj klienta:
UdpClient client = new UdpClient("xxx", 6769);
IPEndPoint ip = null;
byte[] msg = ASCIIEncoding.ASCII.GetBytes(" " + tBox1.Text + ":" + tBox2.Text);
msg[0] = 1;
client.Send(msg, msg.Length);
byte[]data = client.Receive(ref ip);
if (data[0] != 1)
{
//
}
Ogółem serwer ma za zadanie odebrać zapytanie od klienta, następnie je skonsultować z bazą i odpowiedzieć.
Gdzie leży problem?