开发者

How do i check the data sent to the IP Address on particular port?

开发者 https://www.devze.com 2023-03-04 21:46 出处:网络
I am sending data to the IP address 127.0.0.1 on port number 5152. Through socket programming i am sending the data (\"Hello world\") . I am receiving a acknowledgement as sent 51 Bytes. But how do i

I am sending data to the IP address 127.0.0.1 on port number 5152. Through socket programming i am sending the data ("Hello world") . I am receiving a acknowledgement as sent 51 Bytes. But how do i know the data received is correct or not in the above IP address.

I have created a server application , and i am using a same IP and port number here.

// Create our listening socket
//
sListen = socket(AF_INET, SOCK_开发者_如何学GoSTREAM, IPPROTO_IP);
if (sListen == SOCKET_ERROR)
{
    printf("socket() failed: %d\n", WSAGetLastError());
    return 1;
}
// Select the local interface and bind to it
//
if (bInterface)
{
    local.sin_addr.s_addr = inet_addr(szAddress);
    if (local.sin_addr.s_addr == INADDR_NONE)
        usage();
}
else
    local.sin_addr.s_addr = htonl(INADDR_ANY);
local.sin_family = AF_INET;
local.sin_port = htons(iPort);

if (bind(sListen, (struct sockaddr *)&local,
        sizeof(local)) == SOCKET_ERROR)
{
    printf("bind() failed: %d\n", WSAGetLastError());
    return 1;
}

Bind fails with 10048 error.


Depend on what you're connecting to. If it's your application, the fact that the socket opens proves that you already have a listening socket : just display what it receives (or configure the traces on the server to display it).

Another idea when dealing with network development is to monitor actual network traffic using wireshark.


You sent your data - now you need to receive it !

You'll need to create a server that listens on port 5152 on the same box and have it display what it receives from your client.


Your error is "address already in use". That means some other program has the port open. You can see a list of programs listening using "netstat" at the command line. Perhaps that will help you figure it out.

Wireshark is a handy application to see what's being sent via the network. Very handy for debugging these kinds of programs.

0

精彩评论

暂无评论...
验证码 换一张
取 消