WinSock programming

This is a discussion on WinSock programming within the Windows Programming forums, part of the Platform Specific Boards category; Hi folks, I started to learn a WinSock programming, so I want to realise one simple server-client application, both server ...

  1. #1
    Registered User
    Join Date
    Jun 2005
    Location
    Sarajevo, Bosnia and Herzegovina
    Posts
    18

    WinSock programming

    Hi folks, I started to learn a WinSock programming, so I want to realise one simple server-client application, both server and client will be on my own computer,
    because I havn't conditions for different computers and ip addresses. This application simple should to do next staff :server send a some data to client and client should accept it and show that data in some control (edit).
    This what I did in direction of server application:
    Code:
    WSAStartup(version, &wsaData);
        sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        WSAAsyncSelect (sock, hwnd, WM_SOCKET_NOTIFY,  FD_CONNECT | FD_READ | FD_WRITE));
        addr.sin_family = AF_INET;
        addr.sin_port = htons("I don't know what to put here, maybe a 21 FTP ???");
        addr.sin_addr.S_un.S_addr = inet_addr(hostip);
        connect(sock, (SOCKADDR*) &addr, sizeof(addr));
        return TRUE;
    Here is code for getting my ip address:

    Code:
    version = MAKEWORD(2, 0);
            WSAStartup(version, &wsaData);
            gethostname(hostname, 256);
            host = gethostbyname(hostname);
            strcpy(hostname, host->h_name);
            hostip = inet_ntoa(*((in_addr*)host->h_addr));
            MessageBox(NULL, hostname, NULL, NULL);
            MessageBox(NULL, hostip, NULL, NULL);
            WSACleanup();
    Here are a declarations:

    Code:
    static WSADATA wsaData;
    static SOCKET sock;
    static SOCKADDR_IN addr;
    static char received[100];
    static unsigned long ulTime;
    static DWORD wEvent, wError;
    static HOSTENT *host;
    static char hostname[256];
    static char *hostip;
    static WORD version;
    #define WM_SOCKET_NOTIFY (WM_USER + 1)
    So first question, is everithing here ok, so did some line could be better done or is wrong etc, and what port to use in addr.sin_port ??
    Next if this code established a connection (with correct port), what function I must use to send a data to connected computer (example code should be excellent), and what functions must use a client for accepting a sent data (example code again should be great help). Did connection must be a from both side, I mean did client must be connected to a server computer for receiving data or he will just got message for pending data whos was sent to him and he just decide did or not to accept it.
    Thanks again !

  2. #2
    Registered User
    Join Date
    Jun 2005
    Location
    Sarajevo, Bosnia and Herzegovina
    Posts
    18
    Nothing people, I found a solution

  3. #3
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    "Nothing people"?

  4. #4
    Registered User kryptkat's Avatar
    Join Date
    Dec 2002
    Posts
    638
    "and what port to use in addr.sin_port ??"

    What port do you want?

    "what function I must use to send a data to connected computer "

    sendto();
    "and what functions must use a client for accepting a sent data"

    accept();
    listen();

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Winsock issues
    By tjpanda in forum Windows Programming
    Replies: 3
    Last Post: 12-04-2008, 08:32 AM
  2. Winsock Messaging Program
    By Morgul in forum Windows Programming
    Replies: 13
    Last Post: 04-25-2005, 05:00 PM
  3. Winsock - Where do i start?
    By Brain Cell in forum Networking/Device Communication
    Replies: 5
    Last Post: 02-14-2005, 01:39 PM
  4. Where do I initialize Winsock and catch messages for it?
    By Lithorien in forum Windows Programming
    Replies: 10
    Last Post: 12-30-2004, 12:11 PM
  5. winsock
    By pode in forum Networking/Device Communication
    Replies: 2
    Last Post: 09-26-2003, 01:45 AM

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