Thread: socket programming

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    20

    socket programming

    Hi ...

    i made client/server program in that the client send strings to server ,then the server send it back to the server the length of the string that entered by the client ,so i added feature as this

    when the client press "--" the server close the socketfd for that client then the client terminate its program as this

    Client_side> please enter a sequence of characters followed by the new-line character:
    hello students (input from a user)
    Client_side > sending "hello students" to the server
    Client_side > length= 14
    Client_side > please enter a sequence of characters followed by the new-line character:
    And the same happens again until the user quits by typing --.


    Server_side > waiting for client messages.
    Sever_side > reveiced "hello students" from the client (IP address, port #)
    Server_side > Sending "14” to the client
    Server_side > waiting for client messages
    Server_side > received quit from client ...Goodbye (assuming the client typed --)


    but i want to add to server code confirm question that when the user type "--" show the question : "Are you sure to exit Y/N ?"
    if he type "y" then the server close the connfd for that client then the client will exit
    Attached Files Attached Files
    Last edited by zmhnak; 03-01-2013 at 06:16 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Why are you trying to add this to the server code?

    Servers run unattended in the background.
    If there was a place to ask this, it would be in the client code, just before sending the message off to the server.


    Oh, and when you do this
    n = recv( sock, buff, sizeof(buff), 0 );
    you should do this
    n = recv( sock, buff, sizeof(buff)-1, 0 );
    so that you always have room to append the \0.

    Also, make sure you close the socket on the client end, rather than just returning from the function.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Feb 2013
    Posts
    20
    Thnx very muvch for your replay...
    i will try your advice and tell you what will happen...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. About Device Driver Programming And Socket Programming
    By pritesh in forum Linux Programming
    Replies: 6
    Last Post: 01-23-2010, 03:46 AM
  2. HELP socket programming!!
    By Rishi. in forum Linux Programming
    Replies: 12
    Last Post: 08-13-2009, 03:15 AM
  3. Socket programming in C with socket.h
    By funzy in forum Networking/Device Communication
    Replies: 13
    Last Post: 08-29-2008, 04:12 AM
  4. socket programming
    By shraddha in forum Networking/Device Communication
    Replies: 3
    Last Post: 09-11-2005, 11:14 AM
  5. which programming language should be used for socket programming?
    By albert_wong_bmw in forum Networking/Device Communication
    Replies: 8
    Last Post: 06-04-2004, 08:12 PM

Tags for this Thread