|
-
May 9th, 2009, 01:08 AM
#1
Thread Starter
Fanatic Member
-
May 9th, 2009, 11:15 AM
#2
Addicted Member
Re: TCP Server/Client Help
Well what you want to do is have multi-threading.You would also need "Case" System.And of course the tcpclient/tcplistener
Pm Me if you need more help
-
May 17th, 2009, 03:49 AM
#3
Junior Member
Re: TCP Server/Client Help
I'm already researching on client/server program and I'm unable to run the project in that thread also.
Can someone guide us to launch the project?
-
May 17th, 2009, 04:23 AM
#4
Re: TCP Server/Client Help
 Originally Posted by tassa
Hello, I'm a newbie in networking and I was reading this post to see if i could understand how to create a client/server... But I couldn't...
Can anyone help me with this? Or has an example form?
I don't want anything fancy. Just want the client to send the server 4 numbers, depending on the user's choice; after that, the server would turn off the pc, restart it, etc. It all depends on the number received.
Is there a rather "simple" way to do it? If it's not to much trouble you could use Atheist's example. (Btw I don't understand the code and, yes, I've checked on msdn.com)
Thanks a lot to whoever helps me out!  
What is the problem with the code posted in that thread of mine?
 Originally Posted by AereoN
I'm already researching on client/server program and I'm unable to run the project in that thread also.
Can someone guide us to launch the project?
I'll ask you the same question as above 
A note to the both of you, my example includes everything needed to establish a server/client connection, but there is no user interaction. IE it wont show you received messages etc. Thats for you to implement.
(furthermore that particular example is a bit poor and i intend to update it but i never get the time)
-
May 17th, 2009, 04:23 AM
#5
Fanatic Member
Re: TCP Server/Client Help
-
May 17th, 2009, 04:38 AM
#6
Junior Member
Re: TCP Server/Client Help
After i build them, what should i do next?
I tried to use SendMessage function from the client side but nothing happens.
-
May 17th, 2009, 04:43 AM
#7
Re: TCP Server/Client Help
 Originally Posted by AereoN
After i build them, what should i do next?
I tried to use SendMessage function from the client side but nothing happens.
There's a character that denotes the end of a message that you'd need send at the end of your message; ControlChars.Cr. If you do not send this character, the receiving host will expect more data to arrive and so it will not treat the already received data as a complete message.
Once you've got that down, all you must do is handle the dataReceived event and do whatever you wish to do with the received data.
-
May 17th, 2009, 05:00 AM
#8
Junior Member
Re: TCP Server/Client Help
 Originally Posted by Atheist
There's a character that denotes the end of a message that you'd need send at the end of your message; ControlChars.Cr. If you do not send this character, the receiving host will expect more data to arrive and so it will not treat the already received data as a complete message.
Once you've got that down, all you must do is handle the dataReceived event and do whatever you wish to do with the received data.
Thanks. The sending & receiving message works now.
Another question is how do I handle when the client exits the program or lose it's internet connection?
I tried sending "DISCONNECT" & ControlChars.Cr to the Server but an exception still appears.
And let's say if I have few users connected to the server, how do I send a specific message to a certain user instead of broadcasting it?
-
May 17th, 2009, 05:09 AM
#9
Re: TCP Server/Client Help
 Originally Posted by AereoN
Thanks. The sending & receiving message works now.
Another question is how do I handle when the client exits the program or lose it's internet connection?
I tried sending "DISCONNECT" & ControlChars.Cr to the Server but an exception still appears.
Well, seeing as you can never be certain that a connection still exists at the very time you are trying to send/receive something, I believe your only real solution is to use error handling with Try-Catch blocks.
 Originally Posted by AereoN
And let's say if I have few users connected to the server, how do I send a specific message to a certain user instead of broadcasting it?
You will have to think off a good application layer protocol for your client-server project, that is...define the language in which the server and client will communicate.
Perhaps you could choose to specify the name of the receiver first in the message, and then the text to be sent, and let the server parse out the receiver name and route the message on to that particular client. Thats one way to go about it.
-
May 17th, 2009, 07:23 AM
#10
Junior Member
Re: TCP Server/Client Help
 Originally Posted by Atheist
The ideal thing is to have the client send a message whenever it closes down. When the server receives this message it should simply remove him from the list of connected clients.
However, if the client closes because of the system crashing or something of the sort, sending a message is obviously not possible. We will solve this by adding some nifty code when the exception occures in the doRead subroutine. But in order to do this we will need to change the ConnectedClients constructor, I'm going to update the code again..
Edit: There now I've edited the code.
Notice the new constructor in the ConnectedClient class, it takes one more argument, an the instance of Form1.
So upon creating a new ConnectedClient class, (on the doListen subroutine) we pass it like so: New ConnectedClass(incomingClient, Me)
This is because we want to call the new subroutine 'removeClient' from within ConnectedClass, like you can see being done in the doRead subroutine.
I hope this isnt too confusing for you 
^ from your original thread.
Based on that explanation, shouldn't removeClient function will end the connection of the client with the server?
But it's still throwing exception for it.
Another thing that pops in my head is that should I always put an identifier on the clients so that each message on the server can be interpreted correctly?
For example: on my 1st msg from the client, I sent connect|username. then for the next msg do i need to specify something like this? "username|text" or I can identify who sent the message at the server?
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|