Click here to Skip to main content
15,916,945 members
Home / Discussions / C#
   

C#

 
GeneralRe: Problem with Listview,help! Pin
imbiz5-Jun-10 16:02
imbiz5-Jun-10 16:02 
GeneralRe: Problem with Listview,help! Pin
imbiz5-Jun-10 16:21
imbiz5-Jun-10 16:21 
QuestionUsing connection continuously Pin
teknolog1235-Jun-10 6:36
teknolog1235-Jun-10 6:36 
AnswerRe: Using connection continuously Pin
Not Active5-Jun-10 7:02
mentorNot Active5-Jun-10 7:02 
GeneralRe: Using connection continuously Pin
teknolog1235-Jun-10 8:30
teknolog1235-Jun-10 8:30 
GeneralRe: Using connection continuously Pin
Luc Pattyn5-Jun-10 8:50
sitebuilderLuc Pattyn5-Jun-10 8:50 
AnswerRe: Using connection continuously Pin
Luc Pattyn5-Jun-10 7:19
sitebuilderLuc Pattyn5-Jun-10 7:19 
AnswerRe: Using connection continuously Pin
Erik Funkenbusch6-Jun-10 11:01
Erik Funkenbusch6-Jun-10 11:01 
Where to start.. where to start. there's so much wrong with this code that it seems clear you haven't even a basic idea of how execution scopes work, or what happens when you leave a block of code. I'm not criticizing you, but you're lacking some fundamental knowledge here.

First, in your "server" you click a button to start.. ok, but all your code is running within that button click event.. which will lock up your UI on the server until processing is finished. This is probably not what you have in mind for a long running connection. You will most likely have to create a worker thread to handle this code, which I won't go into detail about much here.. but something for you to research into.

Next, you create new NetworkStream and StreamReader/Writer objects within your while loop. This is highly wasteful, and will likely cause a lot of problems. I believe that when the NetworkStream object is destroyed at the end of your while loop, it will close the socket that it's attached to unless you specify false for socket ownership in the constructor. So your first step would be to move those three lines to outside of your while loop (but inside the if statement), that will keep them around while you process things.

Next, you need a way to tell when the socket has been closed. Certainly, your exception handler will do that, but it's not the "correct" way. ReadLine() returns null when the socket is closed. So you should change your code to exit the loop when ReadLine() returns null.

Now on to the client. First, you will probably want to create a "connect" button and a "disconnect" button (or you can get fancy and use the same button for both). This will create the TcpClient connnection and leave it open. The close will close the connection. Then you button click will do nothing but send the text in your textbox. You may want to create a second textbox to display the output that comes back instead of using a MessageBox.
--
Where are we going? And why am I in this handbasket?

QuestionComplex SQL Insert Query Pin
TenRC5-Jun-10 5:05
TenRC5-Jun-10 5:05 
AnswerRe: Complex SQL Insert Query Pin
Not Active5-Jun-10 6:58
mentorNot Active5-Jun-10 6:58 
GeneralRe: Complex SQL Insert Query Pin
TenRC5-Jun-10 13:23
TenRC5-Jun-10 13:23 
QuestionEF question -- get a name of a table [modified] Pin
Lutosław5-Jun-10 4:49
Lutosław5-Jun-10 4:49 
AnswerRe: EF question -- get a name of a table Pin
Not Active5-Jun-10 6:51
mentorNot Active5-Jun-10 6:51 
GeneralRe: EF question -- get a name of a table Pin
Lutosław5-Jun-10 12:14
Lutosław5-Jun-10 12:14 
GeneralRe: EF question -- get a name of a table Pin
Not Active5-Jun-10 13:03
mentorNot Active5-Jun-10 13:03 
GeneralRe: EF question -- get a name of a table Pin
Lutosław5-Jun-10 13:50
Lutosław5-Jun-10 13:50 
GeneralRe: EF question -- get a name of a table Pin
Not Active5-Jun-10 15:18
mentorNot Active5-Jun-10 15:18 
GeneralRe: EF question -- get a name of a table Pin
Lutosław6-Jun-10 4:04
Lutosław6-Jun-10 4:04 
Questionhow to handle Server Not found exception at client side in .net remoting? Pin
amit_834-Jun-10 22:48
professionalamit_834-Jun-10 22:48 
AnswerRe: how to handle Server Not found exception at client side in .net remoting? Pin
#realJSOP5-Jun-10 2:02
professional#realJSOP5-Jun-10 2:02 
Questionoutput confusion Pin
Unknown Ajanabi4-Jun-10 22:03
Unknown Ajanabi4-Jun-10 22:03 
AnswerRe: output confusion Pin
Estys4-Jun-10 22:18
Estys4-Jun-10 22:18 
AnswerRe: output confusion [modified] Pin
DaveyM695-Jun-10 1:35
professionalDaveyM695-Jun-10 1:35 
AnswerRe: output confusion Pin
#realJSOP5-Jun-10 1:58
professional#realJSOP5-Jun-10 1:58 
GeneralRe: output confusion Pin
DaveyM695-Jun-10 2:20
professionalDaveyM695-Jun-10 2:20 

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.