Thread: Need help with winsock

  1. #1
    Programmer Frantic-'s Avatar
    Join Date
    Dec 2004
    Posts
    114

    Need help with winsock

    Ok, im having some problems transfering some functions that worked before into a single header and then making them so that they can be reused. These all worked before with out the variables Im trying to add. Can you see what im doing wrong?

    Example, this section of code
    Code:
    //---------------------------------------------------------------------------
    // XNET_ClientStartup
    //---------------------
    // This function initiates the XNET Client.
    // iport is the port number that you wish to connect to.
    // sipaddress is the ip address you wish to connect to.
    //---------------------------------------------------------------------------
    void XNET_ClientStartup(HANDLE &hsocket, int iport, LPSTR sipaddress){
    	WSADATA wsaData;
        WSAStartup(MAKEWORD(1,1), &wsaData);
    	hsocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
    
    	SockAddr.sin_port = htons(iport);
    
    	SockAddr.sin_family = AF_INET;
    
    	SockAddr.sin_addr.s_addr = inet_addr(sipaddress);
    
    	if (connect(hsocket, (SOCKADDR *)(&SockAddr), sizeof(SockAddr)) != 0)
          {
    		MessageBox(NULL,dbStr(WSAGetLastError()),"XNET Error",MB_OK);
          }
    }
    makes these errors

    Code:
    c:program filesincludexnet.h(27) : error C2440: '=' : cannot convert from 'unsigned int' to 'void *'
            Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
    c:program filesincludexnet.h(29) : error C2065: 'SockAddr' : undeclared identifier
    c:program filesincludexnet.h(29) : error C2228: left of '.sin_port' must have class/struct/union type
    c:program filesincludexnet.h(31) : error C2228: left of '.sin_family' must have class/struct/union type
    c:program filesincludexnet.h(33) : error C2228: left of '.sin_addr' must have class/struct/union type
    c:program filesincludexnet.h(33) : error C2228: left of '.S_un' must have class/struct/union type
    c:program filesincludexnet.h(33) : error C2228: left of '.S_addr' must have class/struct/union type
    c:program filesincludexnet.h(35) : error C2664: 'connect' : cannot convert parameter 1 from 'void *' to 'unsigned int'
            This conversion requires a reinterpret_cast, a C-style cast or function-style cast

  2. #2
    He's trying.
    Join Date
    Apr 2005
    Location
    Missouri, US
    Posts
    70
    I think you'll need to define "SockAddr" before you start setting ports and things.

    sockaddr_in SockAddr;

    After you make the socket.
    (Just guessing though)

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, 04: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, 12:45 AM