How To Pass Two Parameters In "Client.WriteLine" In "SimpleTCP" - c#

So I want to make a chat application in C# using the NuGet module "SimpleTCP", I made it work so the clients can send messages to the server and all clients get those messages but what I want now is to make it so I could pass a name string in the client.WriteLine("Message") when I send a message to the server telling a message was sent("client" is my "SimpleTcpClient" variable).
The problem is that the "WriteLine()" function get only ONE argument so it can't get a Message and Name variables.
I have tried searching google for a solution for that but found nothing.
I also tried just doing "client.WriteLine("This is a message", "Tal M")" but it didn't work.
This is some of the code that tells the client to send a message to the server:
private void SendMessageInput_Click(object sender, EventArgs e)
{
client.WriteLine(MessageInput.Text);
}
This is the lines that makes the server get the message and broadcast it to all other(including the client that send the message) clients:
private void Server_DataReceived(object sender, SimpleTCP.Message e)
{
txtStatus.Invoke((MethodInvoker)delegate ()
{
txtStatus.Text += e.MessageString;
server.Broadcast(String.Format(e.MessageString));
});
}
What I expect is to be able to get a message that includes Two arguments; First one for a message(String), and Second one for a name(String). I would really appreciate getting help, Thanks.

So I found a solution for my problem! All I had to do is just format the String that I send so it would include both Name and Message using client.WriteLine(String.Format("{0}: {1}", "Bob", "Hello World")).
This solution isn't great since I might need to change it to actually get the Name and Message as variables. If I would want to do that I would need to send a JSON object which can work really well but I don't want to do it now(This solution was suggested by #Sir Rufo, Thanks for the help.

Related

Send SMS via Skyp API

I have a c# app and I wish to send an sms to a specfic User whenever I have an update for that User.
I intend to have many different Users.
I heard that it is possible to send SMS via Skype.
I download some sample code but when I run it I got an error saying 'connection refused'.
I also then came across a blog stating that using Skype this way has potential errors like the SMS not getting through or taking days to get through.
I heard also that Skype are not that good with support in this area.
But, I cannot get past this error to find that all out.
If I send the sms directly using Skype's GUI/App then it comes through no problem.
So, is my code correct?
Should I use Skype for this at all?
Has anyone had a similar thing to do and has a better idea?
Thanks.
CODE:
private void button1_Click(object sender, EventArgs e)
{
var sendNumber = "+44-79-7059-0893";
var msgBody = "test message";
SendSMSMessage(sendNumber, msgBody);
}
void SendSMSMessage(string number, string body)
{
try
{
var skype = new SKYPE4COMLib.Skype();
skype.Timeout = 120 * 1000;
var smsType = SKYPE4COMLib.TSmsMessageType.smsMessageTypeOutgoing; //error occurs here
var message = skype.CreateSms(smsType, number);
message.Body = body;
message.Send();
}
catch (Exception ex)
{
}
}
Just in case anyone is following this I got this response from Sjype:
Andrew,
I am guessing your talking about the Desktop API (formally Public API) which was deprecated in December 2013? I would strongly encourage you not to build on this API as anything you build will have a limited shelf life.
Kind regards
Allen Smith
Program Manager
Skype Developer

SignalR 1.0 - send data to a specific client

I want to be able to send messages to a specific client, I have working code but I cannot find a way to identify users, as on each page load/refresh the client id will change, so I cannot rely on that.
I have tried to append a querystring to the connection, but I have only been able to find the querystring of the same context.
This is my hub, and within the send method i want to be able to match the id that is sent in to a particular connection id at the point of sending the message:
public class Chat : Hub
{
public string addMsg()
{
return "";
}
public void Send(string message, string id)
{
Clients.Client(Context.ConnectionId).receiveMessage(message);
}
}
Here is my client code, i want to pass the id of the person to send a message to to the server send method, and use the querystring value of the other connected user to match it to the id i am sending.
var chat = $.connection.chat;
chat.client.receiveMessage = function (message) {
alert("Received from server: " + message);
};
chat.addMsg = function (message) {
};
$("#sendMessage").click(function () {
chat.server.send($('#newMessage').val(), 6);
});
$.connection.hub.qs = "id=1";
$.connection.hub.start().done(function () {
var myClientId = $.connection.hub.id;
var qs = $.connection.hub.qs;
});
I hope my question makes sense, I have been trying to crack this for a while now, below are some links to some of the articles i have used to get to where i am now, I am just missing the last piece of the puzzle, please go easy on me :)
http://weblogs.asp.net/davidfowler/archive/2012/11/11/microsoft-asp-net-signalr.aspx
SignalR- send data to a specific client
https://github.com/SignalR/SignalR/wiki/QuickStart-Hubs
I don't think this is going to work the way you want it to. The connection ID is just that -- an identifier for a particular connection. SignalR itself doesn't know anything about authenticating users. It is, however, built on top of ASP.NET and all of your familiar authentication methods (Windows, Forms, etc.) work as you would expect.
Once ASP.NET has authenticated the user, you have access to this in your hubs as Context.User. It's now up to you to maintain a mapping between this user and one or more connection IDs. Besides browser refreshes, you might need to deal with a user accessing your service from multiple browsers or machines. Sending a message to this user means sending it to all of those browsers and machines.
Jabbr does all this and more. You really should take a look at that code for a good way to implement this.
How about using the Clients.Caller object int he hub, and overriding the OnConnected method:
public override Task OnConnected()
{
Clients.Caller.sendInitMessage(...);
return base.OnConnected();
}

WP7 WebClient cannot find specific server

Ok, maybe this is the dumbest question ever but I really can't understand what's happening :D
I have this simple code:
private void button1_Click(object sender, RoutedEventArgs e)
{
Uri url = new Uri("http://www.something.com/");
WebClient wc = new WebClient();
wc.DownloadStringAsync(url);
wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
}
void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
string result = e.Result;
}
It works well, except for one case (obviously the one that I need), when the address of the server is "ts4.travian.it". In this case I get this error: "The remote server returned an error: NotFound."
The strange thing is that if I write a small console application with basically the same code, it works...any idea?
EDIT: To be more specific, the server return error 403 - Forbidden, but if I try the same code in a Console Application, it works perfectly...don't know what to think..I'm debugging the application on a Nokia Lumia 800
I found the problem finally. The Silverlight framework automatically set the Referer header of the HttpWebRequest, and the server "ts4.travian.it" refused it because it was not correct.
Did you forget to provide the output for that one case?
Edit:
Status code '403' implies that there' something the server doesn't like in your app. Who knows maybe it checks your UA string and sees that you're using IE Mobile i guess. Than he desides not to allow you see the content. Hm?

Cannot send Email in custom workflow sharepoint 2010

I have some trouble when using SPUtility.SendEmail method in a custom workflow.
private void onWorkflowActivated1_Invoked(object sender, ExternalDataEventArgs e)
{
if (SPUtility.IsEmailServerSet(workflowProperties.Site.OpenWeb()))
{
StringDictionary headers = new StringDictionary();
headers.Add("to", "myemailaddress#mailinator.com");
headers.Add("from", "somebody#example.com");
headers.Add("content-type", "text/html");
SPSecurity.RunWithElevatedPrivileges(delegate()
{
bool test = SPUtility.SendEmail(web, headers, "some message body");
});
}
}
in the code's above, the method SPUtility.SendEmail always returning false.
I've even tried to use RunWithElevatedPrivileges, but still the method returns false.
The smtp configuration is not the problem, because the standard email notification when a task is assigned in sharepoint is sent all right.
The strange part is, I have tried this SendEmail method using a timer job, and the method is working perfectly fine.
please somebody help me if there is something i need to add to my method's above.
thanks.
Try to get the web reference in the elevated privileges scope.
I couldn't find the root of this problem.
I decided to do create 2 workflow: the first is to send the email using initiation parameter (build using sharepoint designer). the second one is workflow that initiate the first workflow.
it's now up and running.

How to validate Multiple Ids in the Webservice Method

hai Friends
I am using this coding for validating the emailID online through webservice method.i will get a input a from a textboa and the click the button.but it is validating the emailId only one at a time.how to vaildate multiple EmaiIDs and validate and return the values.or how to split the ids and validate let me know.
The webservice link is http://www.webservicex.net/ValidateEmail.asmx?wsdl
So far my coding is
protected void ValidateEmail_Click(object sender, EventArgs e)
{
ValidateEmail.ValidateEmailSoapClient EmailClient = new ValidateEmail.ValidateEmailSoapClient("ValidateEmailSoap12");
bool bval = System.Convert.ToBoolean(EmailClient.IsValidEmail(txtvalidateEmail.Text));
Response.Write("Email Address is " + bval.ToString());
}
The link you've posted doesn't open here but I will try to answer your question. If the web service has another method that allows you to pass multiple email addresses then you can use this method. If not, you will need to call the web service for each email you are trying to validate which of course might not be very efficient.

Categories

Resources