I have created a console application as a server and also a web application as a client. I am able to sends string to from my web to my console app.
But, I have a problem to send string from my console to my web application. Refer to my code below:
Console Application (SERVER):
public class Echo : WebSocketBehavior
{
protected override void OnMessage(MessageEventArgs e)
{
Console.WriteLine(e.Data);
Send("Received: " + e.Data);
}
}
class Program
{
static void Main(string[] args)
{
WebSocketServer wsv = new WebSocketServer("ws://127.0.0.1:7890");
wsv.AddWebSocketService<Echo>("/Echo");
wsv.Start();
Console.WriteLine("Server Started on ws://127.0.0.1:7890/Echo");
Console.ReadKey();
wsv.Stop();
}
}
Web Application (CLIENT):
i) Model:
public void GetRFIDPhoto()
{
try
{
wc.OnMessage += Wc_OnMessage;
wc.Connect();
wc.Send("RFID_Photo");
}
catch (Exception) { output = "No Connection Found" + Environment.NewLine; }
}
private void Wc_OnMessage(object sender, MessageEventArgs e)
{
output = e.Data;
//received = e.Data;
}
ii) Controller:
public ContentResult GetRFIDPhoto()
{
wb.GetRFIDPhoto();
return Content(wb.output);
}
iii) View:
function GetRFIDPhoto() {
$.ajax({
type: "GET",
url: "/Home/GetRFIDPhoto",
dataType: "text",
success: function (response) {
Output2.value = response;
},
failure: function (response) {
Output2.value = response;
},
error: function (response) {
Output2.value = response;
}
});
}
What did I do wrong here? From Client to Server is no issue. But, I can't get the string from my Server to Client. Please help.