Thread: Peer to Peer Tcp

  1. #1
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587

    Peer to Peer Tcp

    In programs using TCP we usually have a separate client and server.
    Is it possible to have a program using TCP connection to act both as
    server and as client?
    Please help.

  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
    Yes, that is possible.
    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
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587

    Thanks

    Thank you Salem .Can u tell me how please?. Is there any special functions to do it?.
    I encounter the following problem of a graph.

    A-------B---------C

    where A,B,C are nodes where B must act as client to A but server to C.
    Please help me as i am new to C & Socket programming.
    Thanks in advance.
    Last edited by stevesmithx; 09-24-2007 at 06:19 AM.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    So in other words, A and C would normally communicate directly, but B is there to act as a proxy or a filter.
    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.

  5. #5
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    yes like a filter.Can one program(B) listen and connect on two different sockets?

  6. #6
    Registered User
    Join Date
    May 2006
    Posts
    630
    Yes.

  7. #7
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    hi guys,
    Can u please give me some idea about how to solve this with specific functions?

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by stevesmithx View Post
    hi guys,
    Can u please give me some idea about how to solve this with specific functions?
    If you know what functions you need for either end of the communication, you probably would need the same functions for doing a "filter" or "proxy" server.

    If you don't know/understand how to do that, then you probably need to read up a bit on "programming sockets".

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    and the hat of copycat stevesmithx's Avatar
    Join Date
    Sep 2007
    Posts
    587
    All right.Thanks for the help guys.

  10. #10
    Registered User
    Join Date
    Oct 2007
    Posts
    1
    wrt socket programming :

    Local addressing format is used by sockets that are local to your hosts.
    eg : lpr command uses local socket to communicate with spooling service.

    It is possible to use TCP / IP for local communication, but not recommended ( less efficient )

    To communicate betwn nodes : TCP / IP (AF_INET)
    TO communicate with local sockets : Local addressing format ( AF_UNIX)

    Following show communication betwn
    A to B
    betwn B and B
    B to C


    A ---- (IPv4) ---- B ----- (local addressing format) -----B ----- (IPv4) ----- C

    HTH

    Thanks,
    Rohit Kalsarpe

  11. #11
    Malum in se abachler's Avatar
    Join Date
    Apr 2007
    Posts
    3,195

    Actual help

    I would apologize for the tards on this board, but if I did that Id never have time to post anything useful.

    Since you didnt mention information that I woudl need to provide a helpful answer, like what OS (windows or linux) you are using I will go ahead and assume you are programmign for windows.

    The API function you want to use are the following

    WSAStartup()
    socket()
    bind()
    connect()
    listen()
    send()
    recv()


    WSACleanup()

    those will let you make a basic functional tcp connection, from there you can look into the more complex issues fo blocking versus non-blocking, protocol types etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. TCP Header problem (error)
    By nasim751 in forum C Programming
    Replies: 1
    Last Post: 04-25-2008, 07:30 AM
  2. Accessing TCP flags in TCP packets on Linux using C !!
    By vishamr in forum Linux Programming
    Replies: 2
    Last Post: 10-16-2006, 08:48 AM
  3. SSH Hacker Activity!! AAHHH!!
    By Kleid-0 in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 03-06-2005, 03:53 PM
  4. OOP for DirectPlay Peer to Peer program
    By curlious in forum Networking/Device Communication
    Replies: 0
    Last Post: 11-04-2003, 12:21 AM
  5. TCP TIME_WAIT state
    By Engineer in forum A Brief History of Cprogramming.com
    Replies: 1
    Last Post: 12-27-2001, 08:50 AM