Register for your free account! | Forgot your password?

Go Back   elitepvpers > Coders Den > C/C++
You last visited: Today at 11:03

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



login server

Discussion on login server within the C/C++ forum part of the Coders Den category.

Closed Thread
 
Old   #1
 
elite*gold: 0
Join Date: Oct 2010
Posts: 514
Received Thanks: 65
login server

Hi I have a problem.I writes a socket connection on c + +

It is this code

#pragma comment(lib,"ws2_32.lib")
#include <WinSock2.h>
#include <iostream>
#include <stdio.h>
#include <tchar.h>

int _tmain(int argc, _TCHAR* argv[])
{
WSAData wsa;
WORD Version = MAKEWORD(2,1);
WSAStartup(Version, &wsa);

SOCKET Listen = socket(AF_INET, SOCK_STREAM, 0);
SOCKET Connect = socket(AF_INET, SOCK_STREAM, 0);

SOCKADDR_IN Server;

char ip[12] = "86.63.109.231";
int port;

port = 4003;
Server.sin_addr.s_addr = inet_addr(ip);
Server.sin_family = AF_INET;
Server.sin_port = htons(port);

bind(Listen, (SOCKADDR*)&Server, sizeof(Server));

listen(Listen, 1);
int size = sizeof(Server);

std::cout << "--------------------------------------------------------------------------------"
<< " Server connected." << std::endl
<< " Host: " << ip << " : " << port << std::endl
<< "--------------------------------------------------------------------------------" << std::endl;
for(;{
if(Connect = accept(Listen, (SOCKADDR*)&Server, &size)){
std::cout << "Connection accepted from: " << inet_ntoa(Server.sin_addr) << std::endl;
char recvbuf[225];
recv(Connect,recvbuf,225,0);
std::cout << recvbuf << std::endl;
}

}

WSACleanup();
std::cin.get();
return 0;
}


When trying to enable the program,do I see such errors


C:\Documents and Settings\dom\Pulpit\Untitled2.c|3|iostream: No such file or directory|
C:\Documents and Settings\dom\Pulpit\Untitled2.c||In function `main':|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|9|error: `WSAData' undeclared (first use in this function)|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|9|error: (Each undeclared identifier is reported only once|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|9|error: for each function it appears in.)|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|9|error: syntax error before "wsa"|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|11|error: `wsa' undeclared (first use in this function)|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|18|warning: initializer-string for array of chars is too long|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|31|error: syntax error before ':' token|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|37|error: duplicate label `std'|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|31|error: `std' previously defined here|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|37|error: syntax error before ':' token|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|40|error: duplicate label `std'|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|31|error: `std' previously defined here|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|40|error: syntax error before ':' token|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|46|error: duplicate label `std'|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|31|error: `std' previously defined here|
C:\Documents and Settings\dom\Pulpit\Untitled2.c|46|error: syntax error before ':' token|
||=== Build finished: 16 errors, 1 warnings ===|


What can I change in this code?
szymek111 is offline  
Old 09/07/2012, 19:38   #2
 
elite*gold: 0
Join Date: Jul 2010
Posts: 388
Received Thanks: 196
Aside from the fact that your ip buffer is too small for the string, I don't see anything wrong with the code. The compiler can't find iostream, check if your include directories contain the files you include. You file should end on .cpp, not .c as well, if you want to use the STL.
SmackJew is offline  
Old 09/08/2012, 12:26   #3
 
ernilos's Avatar
 
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
Change the name of page for 'main.cpp' and try it.
ernilos is offline  
Old 09/08/2012, 13:09   #4
 
elite*gold: 0
Join Date: Oct 2010
Posts: 514
Received Thanks: 65
I don't understand ;p
szymek111 is offline  
Old 09/08/2012, 13:15   #5


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
Which compiler do you use? Is it properly installed?
MrSm!th is offline  
Old 09/08/2012, 13:27   #6
 
elite*gold: 0
Join Date: Oct 2010
Posts: 514
Received Thanks: 65
Code::Blocks and Microsoft Visual c++
szymek111 is offline  
Old 09/08/2012, 14:28   #7
 
ernilos's Avatar
 
elite*gold: 20
Join Date: Jan 2012
Posts: 766
Received Thanks: 645
Quote:
Originally Posted by szymek111 View Post
I don't understand ;p
Change the name of file(Untield.c) To main.cpp ans try it now..
ernilos is offline  
Old 09/08/2012, 14:38   #8
 
lolix3's Avatar
 
elite*gold: 10
Join Date: Sep 2010
Posts: 348
Received Thanks: 298
I have compiled this code and it works, but you have in you copy 2 syntax errors.

Greetz
lolix3 is offline  
Old 09/08/2012, 15:23   #9


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
Quote:
Originally Posted by szymek111 View Post
Code::Blocks and Microsoft Visual c++
And which one are you using for that program? MSVC oder C::B?
Quote:
Originally Posted by ernilos View Post
Change the name of file(Untield.c) To main.cpp ans try it now..
That doesn't matter.

Quote:
Originally Posted by lolix3 View Post
I have compiled this code and it works, but you have in you copy 2 syntax errors.

Greetz
If it really has syntax errors, it obviously cannot compile.
I didn't find any syntax errors btw.
MrSm!th is offline  
Old 09/08/2012, 15:30   #10
 
elite*gold: 0
Join Date: Jul 2010
Posts: 388
Received Thanks: 196
Quote:
Originally Posted by MrSm!th View Post
That doesn't matter.
Yes it does.

Quote:
Originally Posted by MrSm!th View Post
If it really has syntax errors, it obviously cannot compile.
I didn't find any syntax errors btw.
Code:
char ip[12] = "86.63.109.231";
My posts seem to be invisible.
SmackJew is offline  
Old 09/08/2012, 16:47   #11
 
elite*gold: 0
Join Date: Oct 2010
Posts: 514
Received Thanks: 65
Already everything is ok but when I turn on the debugger.The program sounded for a few seconds and switches off ;/.I have no errors
szymek111 is offline  
Old 09/08/2012, 16:49   #12


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
Quote:
Originally Posted by SmackJew View Post
Yes it does.
You were the one who said that the name of the file does not matter, yourself.
Quote:
Code:
char ip[12] = "86.63.109.231";
My posts seem to be invisible.
That is not a syntax error.
MrSm!th is offline  
Old 09/08/2012, 17:39   #13
 
elite*gold: 0
Join Date: Jul 2010
Posts: 388
Received Thanks: 196
Quote:
Originally Posted by MrSm!th View Post
You were the one who said that the name of the file does not matter, yourself.
Quote:
Originally Posted by Me
Your file should end on .cpp, not .c as well, if you want to use the STL.
Quote:
Originally Posted by MrSm!th View Post
That is not a syntax error.
So your compiler lets you put 14 bytes in a 13 byte buffer? I'd switch if I were you.
SmackJew is offline  
Old 09/08/2012, 18:26   #14


 
MrSm!th's Avatar
 
elite*gold: 7110
Join Date: Jun 2009
Posts: 28,902
Received Thanks: 25,407
Yes, I saw that post, but I didn't mean it. I meant an old post of yours in which you demonstrated that even "whatever.schweineschauze" is possible.
Why the hell should the file name matter for includes? His include-config clearly seems corrupted.

Quote:
Originally Posted by SmackJew View Post
So your compiler lets you put 14 bytes in a 13 byte buffer? I'd switch if I were you.
It's rather a runtime error, if you exceed the range of an array. My compiler complains about such errors, but old compilers (and C::B is shipped with an old one) may ignore them and let you do what you want (afaik C compilers let you fully decide at which index you want to write, but I just heard that from a C coder).
MrSm!th is offline  
Old 09/08/2012, 19:28   #15
 
elite*gold: 0
Join Date: Jul 2010
Posts: 388
Received Thanks: 196
Quote:
Originally Posted by MrSm!th View Post
Yes, I saw that post, but I didn't mean it. I meant an old post of yours in which you demonstrated that even "whatever.schweineschauze" is possible.
Why the hell should the file name matter for includes? His include-config clearly seems corrupted.
It matters in the sense that Code::Blocks, by default, either comes with GCC or no compiler. Code::Blocks calls GCC for you, and chooses GCC's parameters according to your settings, but also according to your files, if you've ever compiled something with GCC you will also know that include directories are passed as an argument as well. My guess is, if you compile a .c file with Code::Blocks it automatically assumes you're compiling C Code, and thus doesn't pass the include directories to gcc which contain C++ headers, like iostream, and frankly, why would it?

The difference between whatever.schweineschnauze, main.cpp and main.c is Code::Blocks assumptions. OP probably opened a C++ project in Code::Blocks. Now if his file was named whatever.schweineschnauze or main.cpp or mycatlikestolickitscrotch.cpp all would be well, Code::Blocks makes the right assumptions and doesn't really care about the file name. If you end your file on .c, as described, Code::Blocks most likely assumes it's C, resulting in the error described.

Quote:
Originally Posted by MrSm!th View Post
It's rather a runtime error, if you exceed the range of an array. My compiler complains about such errors, but old compilers (and C::B is shipped with an old one) may ignore them and let you do what you want (afaik C compilers let you fully decide at which index you want to write, but I just heard that from a C coder).
There's a difference between an error that is detectable during interpretation of the code, like this one, and an error that is not, like copying more bytes than the buffers capacity with strcpy for example. I seriously doubt any compiler, including GCC, most likely used by OP, would compile this. It would be a testament to sloppy design and callousness, if enabled by default.
SmackJew is offline  
Thanks
1 User
Closed Thread


Similar Threads Similar Threads
Warrock Pvp Server Complete Succesfully Game Login But Login Map Error :S
02/22/2011 - WarRock - 7 Replies
Hi friends succesfully warrock pvp server and game login ıd pw succesfully server list WREMU Create room friedns came friends ready game start do not be eniting please help :(
Hot ice Down oder login Server down!!Wenn ja sagt wolfi bescheid dass login down ist
01/01/2010 - Metin2 Private Server - 1 Replies
hallo kann jmnd bescheid sagen bitte



All times are GMT +1. The time now is 11:05.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.