|
This is probably not how I would do it, but if things are as simple as you describe and you don't think it will change in the future, you should be able to make it work.
Your code is basically very similar to the sample code in this MSDN article: http://msdn.microsoft.com/en-us/library/system.net.sockets.socket(v=vs.100).aspx[^].
Notice in SocketSendReceive() how they do the Receive() in a while loop, adding to the final string each time through the loop (if you follow that sample, you might want to use a StringBuilder object instead of just adding onto the string).
I suspect your truncated and left over data issues are due to the fact that you just try to read the data into your fixed size buffer in a single Receive() call. If you don't want to use a while loop in the reading part, you could use the socket objects Available property[^] to see how much data has been received and set the size of your buffer accordingly. It is not something I will recommend because you might have to change the sockets ReceiveBufferSize to be able to receive the largest data block the device can send to you - that can end up being a frustrating back and forth exercise.
Soren Madsen
"When you don't know what you're doing it's best to do it quickly" - Jase #DuckDynasty
|
|
|
|
|
Thanks Soren, yes it is generally known what will be replied and that is all I will ever need to recieve. It was the "Available" that I wanted - I'm now able to read only when there is data as well as clear anything still there.
|
|
|
|
|
You can use the Available property[^] (and others) to check the status of the connection. You should also not assume that your Receive call will get all the data in one go; unless the device sends you an indicator with each message. You should continue to check until there is no more data on the connection.
Use the best guess
|
|
|
|
|
TCP sends messages. You get rid of the message by reading it. All of it.
It gets 'stuck' because it is doing a blocking read because there is nothing left to read.
The simple and correct solution is to read the entire message. If you cannot accurately determine the message size then you have a problem that is likely not solvable.
If the device itself is failing to send a complete message then you can use a timeout to attempt to read the complete message. However that doesn't help on the next message if the rest of the message came in later.
Why not just drop and recreate the connection each time?
|
|
|
|
|
after I run my windows application(c#) program and entering some digits and add to one list(showing one gif image to load) suddenly,after 5 or 6 times the shape of all buttons and labels Gradually change into cross shape.but also this happens in just some computers.thanks very much if you can help me.
|
|
|
|
|
No idea whatsoever. Sorry. As you haven't provided any code for us to look at, there's not a lot we can do.
Have you looked at the eventlog on the affected machines to see if there's anything being written there?
|
|
|
|
|
It might be worth just checking that it doesn't happen with any other application too.
|
|
|
|
|
Hi All,
string pattren = " INC | TRUST | COMPANY | 401K ";
string[] ArrPattern = pattren.Split('|');
above the string array i need to concatenate all the posibilities like below output,
ex:
INC PLAN COMPANY 401K
INC PLAN COMPANY empty
INC PLAN empty 401k
INC PLAN empty empty
INC empty COMPANY 401k
INC empty empty 401k
INC empty empty empty
empty PLAN COMPANY 401k
...
...
...
like these 16 combination....
please share your ideas its very urgent for me...
Regards,
Ram
|
|
|
|
|
sethupathiram wrote: please share your ideas its very urgent for me
So what have you got so far? What code have you written? Which part is causing you a problem?
|
|
|
|
|
|
|
Something like this should work:
static IEnumerable<T[]> BuildCombinations<T>(T[] input)
{
int length = input.Length;
int max = checked(1 << length);
for (int combination = 1; combination < max; combination++)
{
var current = new T[length];
for (int index = 0, bit = 1; index < length; index++, bit <<= 1)
{
if ((combination & bit) != 0)
{
current[index] = input[index];
}
}
yield return current;
}
}
...
string pattern = " INC | TRUST | COMPANY | 401K ";
string[] ArrPattern = pattern.Split('|');
List<string[]> allCombinations = BuildCombinations(ArrPattern);
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
I don't find any other better combinations for it, all the BEST possibilities are mentioned in your thread itself.
|
|
|
|
|
I am getting error
Error 1 The type or namespace name 'Form1' could not be found (are you missing a using directive or an assembly reference?) on the subject while trying to build this with Visual C#:
using System;
using System.Windows.Forms;
using SKYPE4COMLib;
namespace SkypeBing
{
public partial class Form1 : Form
{
private Skype skype;
private const string trigger = "!";
private const string nick = "BOT";
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
skype = new Skype();
skype.Attach(7, false);
skype.MessageStatus +=
new _ISkypeEvents_MessageStatusEventHandler(skype_MessageStatus);
}
private void skype_MessageStatus(ChatMessage msg,
TChatMessageStatus status)
{
string command = msg.Body.Remove(0, trigger.Length).ToLower();
skype.SendMessage(msg.Sender.Handle, nick +
" Says: " + ProcessCommand(command));
}
private string ProcessCommand(string str)
{
string result;
switch (str)
{
case "uli":
result = "http://www.youtube.com/watch?v=VfvBQMqCZw8";
break;
default:
result = "Uliuli";
break;
}
return result;
}
}
}
Whole error:
Error 1 The type or namespace name
That is the whole error.
Line 99 Column 33
modified 13-May-13 10:45am.
|
|
|
|
|
Which line does the error occur on?
Use the best guess
|
|
|
|
|
Error 1 The type or namespace name
That is the whole error.
Line 99 Column 33
|
|
|
|
|
Topias Jäppilä wrote: C:\Users\Topsu\Documents\Visual Studio 2012\Projects\Skaip\Skaip\Program.cs 19 I think you actually mean line 19. However, you also have not shown us the content of Program.cs so we cannot guess what is wrong in there.
Use the best guess
|
|
|
|
|
Well only .cs I have on my project is Form1.cs and that makes me wondering why it says something about Program.cs
|
|
|
|
|
Topias Jäppilä wrote: only .cs I have on my project is Form1.cs Have a look in the Solution Explorer window and you will see a full list of all source files in your project.
Use the best guess
|
|
|
|
|
I have a feeling that you have not included the namespace in program.cs that Form1 is using
i.e.
Form1 Myform = new form();
When you should of possibly done
SkypeBing.Form1 Myform = new SkypeBing.Form1();
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
I am not getting it, on which line does this error occur? Please check your solution explorer to discover it.
|
|
|
|
|
Please help me to do this operations by using Asp.Net
1.Several screens (or one very functional one) to view the data in a variety of ways like by Phase, by ESXHost, by Application.
I think if we have several drop downs for filtering then that would work; so I can choose Phase 1, to show only the databases that will be migrated in Phase 1, then I can choose some other criteria and the screen shows a subset of data etc.
2. The Pre-requisites and Post-Migration checks should show whether the Phase or database migration is ready to start or is ok to complete.
|
|
|
|
|
|
But i am using C# as code behind language to implement operations.
|
|
|
|
|
In that case, please edit your question, and explain exactly what you are trying to achieve.
Use the best guess
|
|
|
|