Click here to Skip to main content
15,886,137 members
Home / Discussions / C#
   

C#

 
NewsRe: Trouble binding with TCP to same local endpoint Pin
Mc_Topaz1-Feb-15 6:39
Mc_Topaz1-Feb-15 6:39 
AnswerRe: Trouble binding with TCP to same local endpoint Pin
Pete O'Hanlon2-Feb-15 6:31
mvePete O'Hanlon2-Feb-15 6:31 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Mc_Topaz2-Feb-15 19:57
Mc_Topaz2-Feb-15 19:57 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Pete O'Hanlon2-Feb-15 23:18
mvePete O'Hanlon2-Feb-15 23:18 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Mc_Topaz2-Feb-15 23:43
Mc_Topaz2-Feb-15 23:43 
AnswerRe: Trouble binding with TCP to same local endpoint Pin
DelphiCoder5-Feb-15 20:12
DelphiCoder5-Feb-15 20:12 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
Mc_Topaz8-Feb-15 8:00
Mc_Topaz8-Feb-15 8:00 
GeneralRe: Trouble binding with TCP to same local endpoint Pin
DelphiCoder11-Feb-15 5:22
DelphiCoder11-Feb-15 5:22 
I always start with the socket, and then work into the client. Also because all of this is Asynchronous, I use onCompleted events. I use the socket’s ConnectAsync() method after first setting up an instance of SocketAsyncEventArgs to pass to the method.

I have noticed a few things though specific to your code, you call tcp.GetStream() without even checking if the client is connected first. I would do something like this:
C#
await tcp.ConnectAsync("host", 12345);
if (tcp.Connected)
{
    using (var stream = tcp.GetStream())
    {
        await stream.ReadAsync(buffer, 0, buffer.Length);
    }
}

I would try giving my buffer a larger starting size than zero, perhaps 10,000. And when reading and writing to the same memory stream, I always reset the stream position back to zero. Otherwise you may find your self writing off the end of the stream or reading behind it.
QuestionConversion of Text Box Hindi Value to Unicode to store in database in hindi Pin
Member 1080107431-Jan-15 21:04
Member 1080107431-Jan-15 21:04 
AnswerRe: Conversion of Text Box Hindi Value to Unicode to store in database in hindi Pin
Afzaal Ahmad Zeeshan31-Jan-15 21:44
professionalAfzaal Ahmad Zeeshan31-Jan-15 21:44 
Questiondatatable method to return no value Pin
User 1138061131-Jan-15 8:06
User 1138061131-Jan-15 8:06 
GeneralRe: datatable method to return no value Pin
PIEBALDconsult31-Jan-15 8:41
mvePIEBALDconsult31-Jan-15 8:41 
GeneralRe: datatable method to return no value Pin
User 1138061131-Jan-15 8:52
User 1138061131-Jan-15 8:52 
AnswerRe: datatable method to return no value Pin
Mycroft Holmes31-Jan-15 21:03
professionalMycroft Holmes31-Jan-15 21:03 
AnswerRe: datatable method to return no value Pin
F-ES Sitecore2-Feb-15 6:31
professionalF-ES Sitecore2-Feb-15 6:31 
QuestionC# SendKeys + - ~ signs? Pin
Linus Agren31-Jan-15 7:38
Linus Agren31-Jan-15 7:38 
AnswerRe: C# SendKeys + - ~ signs? Pin
LLLLGGGG31-Jan-15 12:37
LLLLGGGG31-Jan-15 12:37 
GeneralRe: C# SendKeys + - ~ signs? Pin
Linus Agren1-Feb-15 5:59
Linus Agren1-Feb-15 5:59 
GeneralRe: C# SendKeys + - ~ signs? Pin
LLLLGGGG1-Feb-15 6:49
LLLLGGGG1-Feb-15 6:49 
QuestionC# Pin
Member 1116162531-Jan-15 4:23
Member 1116162531-Jan-15 4:23 
AnswerRe: C# Pin
LLLLGGGG31-Jan-15 4:32
LLLLGGGG31-Jan-15 4:32 
GeneralRe: C# Pin
OriginalGriff31-Jan-15 4:48
mveOriginalGriff31-Jan-15 4:48 
GeneralRe: C# Pin
LLLLGGGG31-Jan-15 5:11
LLLLGGGG31-Jan-15 5:11 
AnswerRe: C# Pin
OriginalGriff31-Jan-15 4:47
mveOriginalGriff31-Jan-15 4:47 
QuestionDrawing semi-transparent polygons in C# for CF Pin
Arturo D. Gentili31-Jan-15 1:25
Arturo D. Gentili31-Jan-15 1:25 

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.