bind/connect to network interface card using FreePascal or other language(s)?

Lets say I have two different active network cards (A and B) on my system and also know their network interfaces information.

How would you connect to Card A for instance using FreePascal?


I just compiled it and executed it, it seems to work. You just need to change the IP addresses and ports and add more error checking.

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <arpa/inet.h>

#define MY_PORT 8564
#define THEIR_PORT 8090

int main()
    int     sockfd;
    struct sockaddr_in myaddr;
    struct sockaddr_in theiraddr;
    int res;

    sockfd = socket(AF_INET, SOCK_STREAM, 0);

    memset(&myaddr, 0, sizeof(struct sockaddr_in));

    myaddr.sin_family = AF_INET;
    myaddr.sin_port = htons((unsigned short)MY_PORT);
    //myaddr.sin_addr = INADDR_ANY; //for any interface

    res = inet_pton(AF_INET, "", &myaddr.sin_addr);

    if (1 == res)
        res = bind(sockfd, (const struct sockaddr *)&myaddr, sizeof(struct sockaddr_in));

        if (0 == res)
            theiraddr.sin_family = AF_INET;
            theiraddr.sin_port = htons((unsigned short)THEIR_PORT);
            inet_pton(AF_INET, "", &theiraddr.sin_addr);
            connect(sockfd, (const struct sockaddr *)&theiraddr, sizeof(struct sockaddr_in));

   return 0;

Need Your Help

JSON.NET Parsing Full Key-Value Pair as Key

c# json custom-attributes

I'm rolling my own ValidateAntiForgeryToken attribute for Web API 2.2 for one of my controllers that processes form data through AJAX calls.

google cloud messaging and push notification to device?

android push-notification google-cloud-messaging

i need to know and understand what is the concept used by google cloud messaging to push notification to the device.