Results 1 to 10 of 10

Thread: TCP Server/Client Help

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 2008
    Location
    Dominican Republic
    Posts
    733

    Question TCP Server/Client Help

    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!
    "In our profession, precision and perfection are not a dispensable luxury, but a simple necessity."
    Niklaus E. Wirth


    Rate any post that helped you, it's a good way of saying thanks
    Please specify your Visual Studio Version!

    Why rating is useful

    My Code Bank Submissions: How to determine Windows Version| Working With Mouse Events | Blocking Input Using API | Get host's IP | Minimize to system tray "animated" | Colored ListBox (custom fonts, colors, highlight) Updated -New Class! | [VS 2008] Strong encryption and hashing class - Updated! 31/August/2009 | Create a shortcut using IWshRuntimeLibrary

  2. #2
    Addicted Member
    Join Date
    Mar 2009
    Posts
    198

    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

  3. #3
    Junior Member
    Join Date
    Apr 2009
    Posts
    30

    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?

  4. #4
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: TCP Server/Client Help

    Quote Originally Posted by tassa View Post
    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?

    Quote Originally Posted by AereoN View Post
    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)
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  5. #5
    Fanatic Member manhit45's Avatar
    Join Date
    May 2009
    Location
    Ha noi - Viet Nam
    Posts
    826

    Re: TCP Server/Client Help

    You can refer this , hope it helps you .

    http://www.codeproject.com/KB/vb/RemoteShutdownX.aspx
    --***----------***-----

    If i help you please rate me.

    Working with Excel * Working with String * Working with Database * Working with array *

    K51 ĐH BÁCH KHOA HÀ NỘI - Khoa CNTT pro.

  6. #6
    Junior Member
    Join Date
    Apr 2009
    Posts
    30

    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.

  7. #7
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: TCP Server/Client Help

    Quote Originally Posted by AereoN View Post
    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8
    Junior Member
    Join Date
    Apr 2009
    Posts
    30

    Re: TCP Server/Client Help

    Quote Originally Posted by Atheist View Post
    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?

  9. #9
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: TCP Server/Client Help

    Quote Originally Posted by AereoN View Post
    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.

    Quote Originally Posted by AereoN View Post
    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.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  10. #10
    Junior Member
    Join Date
    Apr 2009
    Posts
    30

    Re: TCP Server/Client Help

    Quote Originally Posted by Atheist View Post
    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
  •  



Click Here to Expand Forum to Full Width