Click here to Skip to main content
15,917,320 members
Home / Discussions / C#
   

C#

 
AnswerRe: multilanguage support by windows application using C# Pin
V.5-Feb-15 20:15
professionalV.5-Feb-15 20:15 
QuestionTable Adapter Pin
Member 114310155-Feb-15 12:49
Member 114310155-Feb-15 12:49 
SuggestionRe: Table Adapter Pin
Richard MacCutchan5-Feb-15 21:59
mveRichard MacCutchan5-Feb-15 21:59 
QuestionReorganise algorithm Pin
sebyku5-Feb-15 11:27
sebyku5-Feb-15 11:27 
AnswerRe: Reorganise algorithm Pin
DelphiCoder5-Feb-15 17:24
DelphiCoder5-Feb-15 17:24 
QuestionImport C function from DLL with passing FILE stream pointer as parameter Pin
Miloš Križan5-Feb-15 9:26
Miloš Križan5-Feb-15 9:26 
AnswerRe: Import C function from DLL with passing FILE stream pointer as parameter Pin
Richard Andrew x645-Feb-15 14:41
professionalRichard Andrew x645-Feb-15 14:41 
QuestionSocket IAsyncResult - Catch SocketError Pin
sheldons5-Feb-15 8:47
sheldons5-Feb-15 8:47 
Newbie here! I hope I have posted in the write section.

I have been stuck on a socket response and need some help.

I am able to receive the full StringBuilder response for the AsyncCallback if I place a break-point right after the:
client.BeginReceive(state.buffer, 0, state.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);

But if I don't put a break-point in, the code just rips past it and nothing seems to happen and the items are not inserted into db.

Code here:
private static void Receive(Socket client)
{
Logger logger = new Logger();
string responseMSG = string.Empty;
DateTime recTime;
string tracer;
string message;

StateObject state = new StateObject();
state.workSocket = client;
Thread.Sleep(500);
client.BeginReceive(state.buffer, 0, state.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);

if (state.sb.ToString() != "")
{
responseMSG = state.sb.ToString();
if (responseMSG.Length > 77)
{
if (responseMSG.Substring(77, 4) == "2610")
{
recTime = DateTime.Now;
tracer = responseMSG.Substring(126, 6).ToString();
message = responseMSG.Substring(77, responseMSG.Length - 77);

SQLHelper.AddMessageDataToExtractTable("recv", recTime, tracer, message);
}
}
else
{
CurrentState.CurrentReceiveTime = DateTime.Now;
CurrentState.CurrentReceiveTracer = "No Tracer";
CurrentState.CurrentReceiveMessage = responseMSG;
}
}
}

private static void ReceiveCallback(IAsyncResult ar)
{
//Logger logger = new Logger();

try
{
StateObject state = (StateObject)ar.AsyncState;
Socket client = state.workSocket;

int bytesRead = client.EndReceive(ar);

if (bytesRead > 0)
{
state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
client.BeginReceive(state.buffer, 0, state.BufferSize, 0, new AsyncCallback(ReceiveCallback), state);
}
else
{
if (state.sb.Length > 1)
{
response = state.sb.ToString();
}
receiveDone.Set();
}
}
catch (Exception e)
{
//logger.DoLog(string.Format("{0}{1} ", DateTime.Now.ToLongTimeString(), " ReceiveCallback: " + e.ToString()));
}
}
SuggestionRe: Socket IAsyncResult - Catch SocketError Pin
Richard MacCutchan5-Feb-15 21:56
mveRichard MacCutchan5-Feb-15 21:56 
GeneralRe: Socket IAsyncResult - Catch SocketError Pin
sheldons6-Feb-15 5:59
sheldons6-Feb-15 5:59 
GeneralRe: Socket IAsyncResult - Catch SocketError Pin
Richard MacCutchan6-Feb-15 6:01
mveRichard MacCutchan6-Feb-15 6:01 
QuestionWord document converted to image is showing transparent background Pin
Member 103642244-Feb-15 22:27
professionalMember 103642244-Feb-15 22:27 
AnswerRe: Word document converted to image is showing transparent background Pin
BillWoodruff5-Feb-15 0:58
professionalBillWoodruff5-Feb-15 0:58 
AnswerRe: Word document converted to image is showing transparent background Pin
DelphiCoder5-Feb-15 17:50
DelphiCoder5-Feb-15 17:50 
QuestionDataGridView Pin
Member 113627094-Feb-15 21:25
Member 113627094-Feb-15 21:25 
QuestionDataGridView Pin
Member 113627094-Feb-15 21:14
Member 113627094-Feb-15 21:14 
AnswerRe: DataGridView Pin
Richard MacCutchan4-Feb-15 21:34
mveRichard MacCutchan4-Feb-15 21:34 
QuestionStack and heap Pin
Member 111616254-Feb-15 19:49
Member 111616254-Feb-15 19:49 
AnswerRe: Stack and heap Pin
Richard MacCutchan4-Feb-15 21:33
mveRichard MacCutchan4-Feb-15 21:33 
AnswerRe: Stack and heap Pin
OriginalGriff4-Feb-15 22:00
mveOriginalGriff4-Feb-15 22:00 
GeneralRe: Stack and heap Pin
Rob Philpott5-Feb-15 4:53
Rob Philpott5-Feb-15 4:53 
GeneralRe: Stack and heap Pin
DelphiCoder5-Feb-15 17:56
DelphiCoder5-Feb-15 17:56 
AnswerRe: Stack and heap Pin
BillWoodruff5-Feb-15 0:56
professionalBillWoodruff5-Feb-15 0:56 
Questionsetting user permissions to winform controls c# Pin
Member 111236393-Feb-15 23:33
Member 111236393-Feb-15 23:33 
AnswerRe: setting user permissions to winform controls c# Pin
OriginalGriff4-Feb-15 0:06
mveOriginalGriff4-Feb-15 0:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.