Click here to Skip to main content
15,918,808 members
Home / Discussions / C#
   

C#

 
AnswerRe: Interview Questions Pin
Guffa1-Jun-07 0:31
Guffa1-Jun-07 0:31 
GeneralRe: Interview Questions Pin
BINOVAR1-Jun-07 0:34
BINOVAR1-Jun-07 0:34 
QuestionFtpWebRequest Pin
Stevo Z31-May-07 23:15
Stevo Z31-May-07 23:15 
QuestionHopefully my last string interop issue Pin
Russell Jones31-May-07 22:47
Russell Jones31-May-07 22:47 
QuestionReading from a socket Pin
Diego F.31-May-07 22:45
Diego F.31-May-07 22:45 
AnswerRe: Reading from a socket Pin
Le centriste1-Jun-07 2:37
Le centriste1-Jun-07 2:37 
GeneralRe: Reading from a socket Pin
Diego F.4-Jun-07 2:03
Diego F.4-Jun-07 2:03 
GeneralRe: Reading from a socket Pin
Le centriste4-Jun-07 2:38
Le centriste4-Jun-07 2:38 
Hi Diego,

First off, this is a C# forum. It is not that I want to be picky, but I hate looking at VB.NET code, it gives me rash.

Second, your socket reading code is not familiar to me, but this is not the kind of code I would be using. Use a while this way instead:

int nbBytesRead;
while ((nbBytesRead = sock.Receive(bytes_recibidos)) > 0)
{
     datos_recibidos = (System.Text.Encoding.ASCII.GetString(bytes_recibidos)).TrimEnd(Chr(0))

....

}


I don't recommend using the Socket.Poll method in a loop. Use it once before the loop, if you want to see if there is data available. Also, you don't need to check for the Socket.Available method, since if Poll returns true, there is data available to read.

I don't know what your application does, but if you expect the server to return data immediately after connecting to it, there is no need to Socket.Poll your client socket. Just use the Socket.Receive, which blocks until data is available. If in your application you don't want to wait undefinetely for data, use the following code after creating your socket:

// The following code will make a Socket.Receive throw a SocketException
// after 10 seconds with no data coming in.
sock.ReceiveTimeout = 10000; // 10 seconds (10000 milliseconds)


Good luck.

-----

Formerly MP(2)

If atheism is a religion, then not collecting stamps is a hobby. -- Unknown

GeneralForgot to mention Pin
Le centriste4-Jun-07 2:54
Le centriste4-Jun-07 2:54 
GeneralRe: Forgot to mention Pin
Diego F.4-Jun-07 7:35
Diego F.4-Jun-07 7:35 
GeneralRe: Reading from a socket Pin
Diego F.4-Jun-07 4:17
Diego F.4-Jun-07 4:17 
GeneralRe: Reading from a socket Pin
Le centriste4-Jun-07 6:51
Le centriste4-Jun-07 6:51 
QuestionUML generator Pin
Fatbuddha 131-May-07 22:40
Fatbuddha 131-May-07 22:40 
AnswerRe: UML generator Pin
Paul Conrad1-Jun-07 13:33
professionalPaul Conrad1-Jun-07 13:33 
Questionc# mouse hooks Pin
Mr Withers31-May-07 22:31
Mr Withers31-May-07 22:31 
QuestionData type conversions problem Pin
Michael10131-May-07 22:26
Michael10131-May-07 22:26 
AnswerRe: Data type conversions problem Pin
Martin#31-May-07 22:43
Martin#31-May-07 22:43 
AnswerRe: Data type conversions problem Pin
Christian Graus31-May-07 23:06
protectorChristian Graus31-May-07 23:06 
GeneralRe: Data type conversions problem Pin
Michael1013-Jun-07 13:04
Michael1013-Jun-07 13:04 
QuestionHow to show and hide a layer in a Visio shape Pin
asithabk31-May-07 21:37
asithabk31-May-07 21:37 
QuestionBeginInit() and EndIinit() performance Pin
Tavbi31-May-07 21:20
Tavbi31-May-07 21:20 
AnswerRe: BeginInit() and EndIinit() performance Pin
Martin#31-May-07 21:40
Martin#31-May-07 21:40 
GeneralRe: BeginInit() and EndIinit() performance Pin
Tavbi31-May-07 22:44
Tavbi31-May-07 22:44 
GeneralRe: BeginInit() and EndIinit() performance Pin
Martin#31-May-07 22:46
Martin#31-May-07 22:46 
GeneralRe: BeginInit() and EndIinit() performance Pin
DavidNohejl1-Jun-07 2:07
DavidNohejl1-Jun-07 2:07 

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.