|
I have found the problem using debug and it was my own silly mistake.
I was using the code:
for(int i = 0; i < DataGridView1.Rows.Count; i++)
{
DataGridView1.Rows[i].Cells[1].Value = Decrypt(DataGridView1.Rows[0].Cells[1].Value.ToString());
}
As you can see each row was getting the value of the first row. So on the first row it was decrypting the string but on the second line it was trying to decrypt the first row that it had already decrypted. Hence the error.
I think I need a break that was quite embarrassing.
Thanks again for your help.
|
|
|
|
|
We all do it - I read what I meant to write all the damn time ...
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
|
Hey!
It would be great if you can share the document that is being fed to the ChatBot — the root cause for the "html" is not declared. It is hard to debug it this way, you can read the output of that request and share it here.
And never share the credential on the internet (your SO thread has the credential of your MVP-based profile), and avoid sharing the email address unless you want spam in your inbox.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
From the Error,
Still had one page of Login Page
|
|
|
|
|
Right, so it was at login attempt?
Consider using AD or something to delegate the authentication programmatically.
The sh*t I complain about
It's like there ain't a cloud in the sky and it's raining out - Eminem
~! Firewall !~
|
|
|
|
|
any sample source code for AD login?
|
|
|
|
|
|
On Premise can use Azure AD?
|
|
|
|
|
|
On Premise AD and Azure AD had integrated. But how to retrieve the data from SharePoint?
from ChatBot?
|
|
|
|
|
The below code i found in some websites but it always return error
multicast_id":6719893729607364541,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
Code is:
WebRequest tRequest = WebRequest.Create("https:
tRequest.Method = "post";
tRequest.Headers.Add(string.Format("Authorization: key={0}", "Server key"));
tRequest.Headers.Add(string.Format("Sender: id={0}", "Sender Id"));
tRequest.ContentType = "application/json";
var payload = new
{
to = "//topics//news",
priority = "high",
content_available = true,
notification = new
{
body = "Test",
title = "Test",
badge = 1
},
data = new
{
key1 = "value1",
key2 = "value2"
}
};
string postbody = JsonConvert.SerializeObject(payload).ToString();
Byte[] byteArray = Encoding.UTF8.GetBytes(postbody);
tRequest.ContentLength = byteArray.Length;
using (Stream dataStream = tRequest.GetRequestStream())
{
dataStream.Write(byteArray, 0, byteArray.Length);
using (WebResponse tResponse = tRequest.GetResponse())
{
using (Stream dataStreamResponse = tResponse.GetResponseStream())
{
if (dataStreamResponse != null) using (StreamReader tReader = new StreamReader(dataStreamResponse))
{
String sResponseFromServer = tReader.ReadToEnd();
this.Label.Text = sResponseFromServer;
}
}
}
|
|
|
|
|
Quote: it always return error
What error?
Is there any message?
Where does the error occur?
What have you done to find out why?
What did the debugger show you was happening?
Remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you type to work with.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
This the error:
multicast_id":6719893729607364541,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"InvalidRegistration"}]}
Success 0
Failure 1
|
|
|
|
|
Member 4773987 wrote: The below code i found in some websites but it always return error Then I suggest you throw it away and use the Google documentation to understand how to use their API correctly.
|
|
|
|
|
Doesn't that mean ... learning stuff? Nobody does that any more, bro - just grab what you need from SO and chuck it together.
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
Thank you for your Help
🤣🤣🤣
|
|
|
|
|
I am trying to make two clients behind NAT communicates each other using a server with port forward working, my scenario:
Server start listering on port 45000 for Client_A connection;
Server Start listering on port 45001 for Client_B connection;
Client_A connect to server on port 45000 and send hello message;
Client_B connect to server on port 45001 and send hello message;
Server Receive hello message from Client_B and send message with Client_B external port (ex 56000) to Client_B;
Client_B receive external port and start listering on port 56000;
Server Receive hello message from Client_A and send message with Client_B IP and port to Client_A;
Client_A receive IP and Port of Client_B;
Client_A connect to Client_B and send hello message
The problem:
Client_B does not receive message from Client_A;
Here is code:
Server:
static int server_A_Port = 45000;
static int server_B_Port = 45001;
static UdpClient server_A;
static UdpClient server_B;
static bool client_B_Connected = false;
static string client_A_Ip = "";
static string client_B_Ip = "";
static int client_A_Port = 0;
static int client_B_Port = 0;
static Thread Server_A_Thread = new Thread(Start_Server_A);
static Thread Server_B_Thread = new Thread(Start_Server_B);
static void Main(string[] args)
{
Server_A_Thread.Start();
Server_B_Thread.Start();
}
static void Start_Server_A()
{
Console.WriteLine("Starting Server_A on port: " + server_A_Port);
server_A = new UdpClient();
IPEndPoint client_A_IpEp = new IPEndPoint(IPAddress.Any, server_A_Port);
server_A.Client.Bind(client_A_IpEp);
Console.WriteLine("Server Started. Waiting Client_A Message");
string c_a = "";
while (string.IsNullOrEmpty(c_a))
{
try
{
c_a = ReceiveMessageFromClient(server_A, ref client_A_IpEp);
Console.WriteLine("Message received from Client_A: " + c_a);
client_A_Ip = ((IPEndPoint)client_A_IpEp).Address.ToString();
client_A_Port = ((IPEndPoint)client_A_IpEp).Port;
server_A.Connect(client_A_IpEp);
}
catch(Exception err)
{
Thread.Sleep(1000);
}
}
Console.WriteLine("Waiting Client_B connection");
bool sended = false;
while (!sended)
{
if(client_B_Connected)
{
Console.WriteLine("Client_B connected, sending Client_B IP and Port to Client_A");
SendMessageToClient(server_A, client_B_Ip + ":" + client_B_Port);
sended = true;
Console.WriteLine("Message Sended to Client_A");
break;
}
Thread.Sleep(1000);
}
Console.ReadLine();
}
static void Start_Server_B()
{
Console.WriteLine("Starting Server_B on port: " + server_B_Port);
server_B = new UdpClient();
IPEndPoint client_B_IpEp = new IPEndPoint(IPAddress.Any, server_B_Port);
server_B.Client.Bind(client_B_IpEp);
Console.WriteLine("Server Started. Waiting Client_B Message");
string c_b = "";
while (string.IsNullOrEmpty(c_b))
{
try
{
c_b = ReceiveMessageFromClient(server_B, ref client_B_IpEp);
Console.WriteLine("Message received from Client_B: " + c_b);
client_B_Ip = ((IPEndPoint)client_B_IpEp).Address.ToString();
client_B_Port = ((IPEndPoint)client_B_IpEp).Port;
server_B.Connect(client_B_IpEp);
client_B_Connected = true;
}
catch (Exception err)
{
Thread.Sleep(1000);
}
}
Console.WriteLine("Sending external Port to Client_B start listering");
SendMessageToClient(server_B,client_B_Port + "");
}
static void SendMessageToClient(UdpClient client, string message)
{
byte[] data = Encoding.GetEncoding(28591).GetBytes(message);
client.Send(data, data.Length);
}
static string ReceiveMessageFromClient(UdpClient client, ref IPEndPoint ep)
{
byte[] data = client.Receive(ref ep);
string receivedString = Encoding.GetEncoding(28591).GetString(data);
return receivedString;
}
Client_A:
static string serverIp = "X.X.X.X";
static int serverPort = 45000;
static string otherClientIp = "0.0.0.0";
static int otherClientPort = 0;
static UdpClient client = new UdpClient();
static void Main(string[] args)
{
Console.WriteLine("Connecting to server...");
client.Connect(serverIp, serverPort);
Console.WriteLine("Connected. Sending request message...");
SendMessageToServer();
Console.WriteLine("Sended. Waiting response...");
string s = "";
while (string.IsNullOrEmpty(s))
{
try
{
s = ReceiveMessageFromServer();
Console.WriteLine("Response received from server.");
}
catch (Exception err)
{
Thread.Sleep(1000);
}
}
string[] otherClientInfo = s.Split(':');
otherClientIp = otherClientInfo[0];
otherClientPort = int.Parse(otherClientInfo[1]);
Console.WriteLine("Other Client info: " + otherClientIp + ":" + otherClientPort);
Thread.Sleep(2000);
Console.WriteLine("Connecting to Client_B...");
client.Connect(otherClientIp, otherClientPort);
Console.WriteLine("Connected. Sending hello hessage...");
SendMessageToClient();
Console.WriteLine("Sended. Waiting response...");
string c = "";
while (string.IsNullOrEmpty(c))
{
try
{
IPEndPoint ep = (IPEndPoint)client.Client.RemoteEndPoint;
c = ReceiveMessageFromClient(client,ref ep);
Console.WriteLine("Response received from Client_B.");
Console.WriteLine("Response: " + c);
Console.ReadLine();
}
catch (Exception err)
{
Thread.Sleep(1000);
}
}
}
static void SendMessageToServer()
{
byte[] data = Encoding.GetEncoding(28591).GetBytes("FROM CLIENT TO SERVER");
client.Send(data, data.Length);
}
static void SendMessageToClient()
{
byte[] data = Encoding.GetEncoding(28591).GetBytes("FROM CLIENT_A TO CLIENT_B");
client.Send(data, data.Length);
}
static string ReceiveMessageFromServer()
{
IPEndPoint serverIpEp = new IPEndPoint(IPAddress.Parse(serverIp), serverPort);
byte[] data = client.Receive(ref serverIpEp);
string receivedString = Encoding.GetEncoding(28591).GetString(data);
return receivedString;
}
static string ReceiveMessageFromClient(UdpClient server, ref IPEndPoint ep)
{
byte[] data = server.Receive(ref ep);
string receivedString = Encoding.GetEncoding(28591).GetString(data);
return receivedString;
}
Client_B:
static string serverIp = "X.X.X.X";
static int serverPort = 45001;
static UdpClient client = new UdpClient();
static void Main(string[] args)
{
Console.WriteLine("Connecting to server...");
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
client.Connect(serverIp, serverPort);
Console.WriteLine("Connected. Sending request message...");
SendMessageToServer();
Console.WriteLine("Sended. Waiting response...");
string s = "";
while (string.IsNullOrEmpty(s))
{
try
{
s = ReceiveMessageFromServer();
Console.WriteLine("Response received from server.");
}
catch (Exception err)
{
Thread.Sleep(1000);
}
}
Console.WriteLine("My External Port: " + s);
IPEndPoint ep = new IPEndPoint(IPAddress.Any, int.Parse(s));
Console.WriteLine("Start Binding on Extenal Port: " + ep.Port);
UdpClient server = new UdpClient();
server.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
server.Client.Bind(ep);
Console.WriteLine("Started. Waiting hello message...");
string c = "";
while (string.IsNullOrEmpty(c))
{
try
{
c = ReceiveMessageFromClient(server, ref ep);
Console.WriteLine("Response received from Client_A.");
Console.WriteLine("Response: " + c);
client.Connect(ep);
Console.ReadLine();
}
catch (Exception err)
{
}
}
Console.WriteLine("Sending message to Client_A...");
SendMessageToClient();
Console.WriteLine("Sended.");
Console.ReadLine();
var myRule = FirewallManager.Instance.Rules.SingleOrDefault(r => r.Name == "TEST_RULE");
FirewallManager.Instance.Rules.Remove(myRule);
}
static void SendMessageToServer()
{
byte[] data = Encoding.GetEncoding(28591).GetBytes("FROM CLIENT TO SERVER");
client.Send(data, data.Length);
}
static void SendMessageToClient()
{
byte[] data = Encoding.GetEncoding(28591).GetBytes("FROM CLIENT_B TO CLIENT_A");
client.Send(data, data.Length);
}
static string ReceiveMessageFromServer()
{
IPEndPoint serverIpEp = new IPEndPoint(IPAddress.Parse(serverIp), serverPort);
byte[] data = client.Receive(ref serverIpEp);
string receivedString = Encoding.GetEncoding(28591).GetString(data);
return receivedString;
}
static string ReceiveMessageFromClient(UdpClient server, ref IPEndPoint ep)
{
byte[] data = server.Receive(ref ep);
string receivedString = Encoding.GetEncoding(28591).GetString(data);
return receivedString;
}
modified 4-Jan-20 23:46pm.
|
|
|
|
|
It's "empty" on Client A as "server". (I think you should have just "one" server)
static void OnClientConnect(object obj)
{
}
It was only in wine that he laid down no limit for himself, but he did not allow himself to be confused by it.
― Confucian Analects: Rules of Confucius about his food
|
|
|
|
|
Sorry i have posted wrong code, now are correct.
|
|
|
|
|
Since NAT is involved, did you setup a rule in your NAT engine which allows clientB to directly connect to clientA, and vice-versa?
You should check the log of the NAT equipment and search for dropped or refused packets from clientB's network to clientA's network.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|
|
If i add rule to Port Forward external ports on Client_B and Client_A, the Client_B can successfully connect to Client_A.
But i need to make this work on nat routers that I don't have access to the settings so I need to make it work without port foward.
Checking the Router(Nat equipment) not show any info from dropped/refused packets but I think it's because it's not a good router.
Sorry for bad english.
|
|
|
|
|
If your software will have to work in environments where you cannot control the NAT configuration, then you will have to rethink the way it works: have each client talk to the server only, and let the server play the role of transmitting messages between clients.
"Five fruits and vegetables a day? What a joke!
Personally, after the third watermelon, I'm full."
|
|
|
|