Yeronox's Profile User Rating: -----

Reputation: 2 Apprentice
Group:
Active Members
Active Posts:
99 (0.11 per day)
Joined:
12-March 12
Profile Views:
2,004
Last Active:
User is offline Apr 30 2014 01:30 PM
Currently:
Offline

Previous Fields

Country:
Who Cares
OS Preference:
Who Cares
Favorite Browser:
Who Cares
Favorite Processor:
Who Cares
Favorite Gaming Platform:
PC
Your Car:
Who Cares
Dream Kudos:
0
Icon   Yeronox is learning PHP!

Posts I've Made

  1. In Topic: UDP Server: weird connections

    Posted 24 Apr 2014

    Is it OK if I use
    inet_addr("192.168.1.100");
    
    ?
  2. In Topic: UDP Server: weird connections

    Posted 24 Apr 2014

    Well, I'm using Code::Blocks and it's building and opening it.. I've added "-lws2_32" to the linker tab too.
  3. In Topic: UDP Server: weird connections

    Posted 24 Apr 2014

    #include <stdio.h>
    #include <stdlib.h>
    #include <winsock2.h>
    
    #define PORT        7890
    #define RECV_BUFFER 100
    
    int main()
    {
        WSADATA wsaData;
        SOCKET RecvSocket;
        SOCKET SenderSocket;
        SOCKADDR_IN RecvAddr;
        SOCKADDR_IN SenderAddr;
        int SenderAddrLen = sizeof(SenderAddr);
        int SenderSockLen = sizeof(SenderSocket);
    
        WSAStartup(MAKEWORD(2,2), &wsaData);
        if ((RecvSocket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == SOCKET_ERROR)
            exit(1);
    
        RecvAddr.sin_addr.s_addr = htonl("192.168.1.101");
        RecvAddr.sin_family = AF_INET;
        RecvAddr.sin_port = htons(PORT);
    
        if(bind(RecvSocket, (SOCKADDR*)&SenderAddr, SenderAddrLen) < 0)
            exit(2);
    
        char buffer[RECV_BUFFER];
        int i, recv_len;
        while (1)
        {
            memset(buffer,'\0', RECV_BUFFER);
            if((recv_len = recvfrom(RecvSocket, &buffer, RECV_BUFFER, 0, (SOCKADDR*)&SenderAddr, &SenderAddrLen)) < 0)
                exit(3);
            for(i = 0; i < RECV_BUFFER; i++)
                printf("%c", buffer[i]);
            printf("\nReceived from %s:%d\n", inet_ntoa(SenderAddr.sin_addr), ntohs(SenderAddr.sin_port));
            sendto(SenderSocket, "\nI've got your data!\n", sizeof("I've got your data!")+2, 0, (SOCKADDR*)&SenderAddr, sizeof(SenderAddr));
        }
        closesocket(RecvSocket);
        WSACleanup();
    }
    
    

    Same issues
    EDIT: sorry, I get this error in the build log:
    Process terminated with status 2 (0 minute(s), 1 second(s))

    What's wrong? I think the bind() should work..
  4. In Topic: {Book} Beginning Visual C# 2012 vs C# 5.0 in a nutshell

    Posted 28 Jul 2013

    I thought to start with Head First C# and then move to C# 5.0 in a Nutshell, but I'd like to buy them together.
    So, does it seem good to you? Would you start with another book?
  5. In Topic: Problem when posting into the DB

    Posted 15 Jul 2013

    I don`t see how to edit my code, as every time I do it, I get an error

My Information

Member Title:
D.I.C Head
Age:
Age Unknown
Birthday:
Birthday Unknown
Gender:
Programming Languages:
C++, PHP

Contact Information

E-mail:
Private

Friends

Comments

Yeronox has no profile comments yet. Why not say hello?