Socket programming in C on windows 7

This is a discussion on Socket programming in C on windows 7 within the Networking/Device Communication forums, part of the General Programming Boards category; Hi Everyone, I have an issue using UDP port. There are mainly two applications. Let's say application 'A' uses port ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    1

    Socket programming in C on windows 7

    Hi Everyone,

    I have an issue using UDP port. There are mainly two applications. Let's say application 'A' uses port 'X' to transmit packets on which application 'B' is bound to read data. Similarly application 'B' uses port 'Y' to transmit packets on which application 'A' is bound to read data. This works perfectly fine.

    Now according to the requirements, I have to run two instances of application 'B' such that only one instance of application 'B' is communicating to application 'A' at a point of time. Now say that the first instance of application 'B' is 'B1' and the second as 'B2'. Then the sequence goes as:
    1- 'A' opens TX port 'X' and RX port 'Y' and bind to 'Y'.
    2- 'B1' opens TX port 'Y' and RX port 'X' and bind to 'X'.
    3- Now both applications start communicating and transfer the data across as required.
    4- When application 'B1' is done sending and receiving the data, it closes its TX and RX ports i.e. Ports 'X' and 'Y'.
    5- Then 'B2' opens TX port 'Y' and RX port 'X' and bind to 'X'.
    6- Now 'B2' starts communicating to application 'A'.
    7- As application 'B2' is done, it closes its TX and RX ports i.e. ports 'X' and 'Y'.
    8- After this, application 'B1' again needs to communicate with application 'A'. So it opens its TX port 'Y' and RX port 'X' and bind to 'X'.

    Everything goes fine till here. The problem starts here.

    9- Now application 'B1' sends a message to application 'A' which application 'A' successfully receives at port 'Y'.
    10- In reply, application 'A' sends a message to application 'B1'. Although application 'A' writes the data successfully at port 'X' but it never reaches to application 'B1' which is waiting for the reply.

    Kindly let me know the possible reason for this issue and the fix. A prompt response would be highly appreciated.

    Thanks,

  2. #2
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    First, is there some special reason you are opening separate Tx and Rx ports?
    It's not wrong, but it may not be necessary. The disadvantage is that the server always has to know where to reply to and I'm thinking it's getting confused.

    In your code are you using recv or recvfrom? send or sendto?
    It sound from your description that your server is losing track of client IPs and perhaps dispatching it's replies to the wrong client, which is no longer there.

    My strategy with single server, multiple client applications is somewhat different than yours.

    I will open a single port on the server which is known to the clients.
    Each client then opens a single port which is not known to the server.
    Multiple clients on the same machine each open single ports on different numbers.

    The server uses recvfrom, taking the return address for it's reply from the incoming packet.
    It then uses sentto to transmit reply packets to the ip/port derived from the incoming packet.

    The server never actually needs to know where it's clients are or how many clients it is communicating with. It's just answering whatever comes in it's port.

    Unless the app is streaming large amounts of data --eg. live audio-- I see no reason to work with multiple ports per client.

    Hope this is helpful....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. socket programming question, closing sockets...
    By ursula in forum Networking/Device Communication
    Replies: 2
    Last Post: 05-31-2009, 06:17 PM
  2. Just starting Windows Programming, School me!
    By Shamino in forum Windows Programming
    Replies: 17
    Last Post: 02-22-2008, 08:14 AM
  3. how to make a windows application
    By crvenkapa in forum C++ Programming
    Replies: 3
    Last Post: 03-26-2007, 10:59 AM
  4. Question..
    By pode in forum Windows Programming
    Replies: 12
    Last Post: 12-19-2004, 07:05 PM
  5. IE 6 status bar
    By DavidP in forum Tech Board
    Replies: 15
    Last Post: 10-23-2002, 06:31 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21