4 Replies - 7812 Views - Last Post: 20 October 2008 - 04:09 PM Rate Topic: -----

#1 UG Cyber   User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 628
  • Joined: 24-July 08

Making a TCP server

Post icon  Posted 20 October 2008 - 09:03 AM

Well i have been working on this for some time now, and i need this server for my debugging on other programs. Basicly it asks you for a port number and starts the server. But recently when trying to re-compile it, i just get a build error
C:\Users\Administrator\Desktop\WinsockTests\Server\MakeFile.win	  Build error 1



this is the code
#include <iostream>
#include <winsock2.h>
#include <windows.h>

using namespace std;

void startServer(int PortNo)
   {
        char recvBuff[1024];
        WSADATA  wsadata;
        int error;
        error=WSAStartup(0x0202, &wsadata);
        if (error)
        {
           cout << "Error occured on step 1";
           system("pause");
        }
        if (wsadata.wVersion != 0x0202)
        {
                             WSACleanup();
                             system("echo Error occured on step two");
                             system("pause");
        }


        char ServerName[30];
        gethostname(ServerName,30);
        SOCKET s;
        cout << "(Server) " << ServerName << " is started on port " << PortNo;

        SOCKADDR_IN Server;

        Server.sin_family = AF_INET;
        Server.sin_port = htons (PortNo);
        Server.sin_addr.s_addr = inet_addr ("0.0.0.0");
        s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
        if (s == INVALID_SOCKET)
        {
              cout << "Error occured on step 'TARGET'";
              system("pause");
        }
        if (bind(s, (SOCKADDR *)&Server, sizeof(Server)) == SOCKET_ERROR)
        {
           cout << "Error Binding" << endl;
           system("pause");
        }

        cout << endl << "Waiting for client response" << endl << endl;

        
     while (true)
     {
        listen(s,2);
        accept(s,NULL,NULL);

         SOCKADDR_IN saClient;

         memset(recvBuff, 0, sizeof(recvBuff));
         int nRet = recv(s,recvBuff,1024,0);


         cout << "Client said:  ";
        cout << recvBuff << endl;
     }

    closesocket(s);
    }
    
    int main(void)
    {
        int Port;
        cout << "Port desired: ";
        cin >> Port;
        startServer(Port);
    }



Is This A Good Question/Topic? 0
  • +

Replies To: Making a TCP server

#2 homemade-jam   User is offline

  • Gabe's Nemesis
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,300
  • Joined: 17-March 08

Re: Making a TCP server

Posted 20 October 2008 - 11:27 AM

Have you tried deleting that (after backing up) .win file and then recompiling?
Was This Post Helpful? 0
  • +
  • -

#3 UG Cyber   User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 628
  • Joined: 24-July 08

Re: Making a TCP server

Posted 20 October 2008 - 11:35 AM

View Posthomemade-jam, on 20 Oct, 2008 - 11:27 AM, said:

Have you tried deleting that (after backing up) .win file and then recompiling?



yes... It didnt make any difference. Should i re-install dev??

[edit] Can someone else compile it and tell me if there is something wrong with the code or my compiler.....please

This post has been edited by UG Cyber: 20 October 2008 - 11:36 AM

Was This Post Helpful? 0
  • +
  • -

#4 homemade-jam   User is offline

  • Gabe's Nemesis
  • member icon

Reputation: 11
  • View blog
  • Posts: 1,300
  • Joined: 17-March 08

Re: Making a TCP server

Posted 20 October 2008 - 01:03 PM

Yeah I'll give it a go tmos, I've got DevCPP

Meanwhile

Otherwise it seems to be a permissions thing
Was This Post Helpful? 0
  • +
  • -

#5 UG Cyber   User is offline

  • D.I.C Addict

Reputation: 38
  • View blog
  • Posts: 628
  • Joined: 24-July 08

Re: Making a TCP server

Posted 20 October 2008 - 04:09 PM

Well i am at school right now, but when i get home i am going to try and compile This code agen (Just the server side) that should tell me if it is the compiler or the code....
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1