Help with sockets

C

CAwehking

Hello, I'm having some troubles with sockets in C++!
1. Do i really need VC++? or could i just use Dev-C++?
2. How do I link winsock to my project?
3. I've never actually made a socket before! I'm trying to find
something that will actually work! without changing to another
programming language!

So could someone help me? I just need a very simple server and client
without to much of a hassle or frustration! I don't need anything big
like couple Gs. Only a couple megabytes for a file. I only want a
something that one person puts a file on, and another person downloads
it. Though i'm not sure if i would like multi-thread?! Could someone
help me? I'm really having troubles with sockets.
PLEASE reply soon! =)
 
J

jason.cipriani

1. Do i really need VC++? or could i just use Dev-C++?

You can use either one you want.
2. How do I link winsock to my project?

The library you want is called ws2_32.lib. How, specifically, you link
to it depends on the linker and IDE you are using. Most IDE's let you
specify this in the project options or build settings in the linker-
related section. In VS 2005 Express, go to the project properties,
then Configuration Properties -> Linker -> Input and add "ws2_32.lib"
to "Additonal Dependencies". In Dev-C++ it's probably similar, or you
have to add the lib to your project or something. I don't know, check
the docs for your IDE.
3. I've never actually made a socket before! I'm trying to find
something that will actually work! without changing to another
programming language!

The concepts will be the same in many, although not all, of the
programming languages that you would try. Here is a great general
tutorial on socket programming. Read it in its entirety. It is
relatively short, really easy to read, and covers a lot of topics.

http://www.beej.us/guide/bgnet/output/html/singlepage/bgnet.html

For all the Windows-specific stuff, and other general references,
visit http://msdn.microsoft.com. Here is a link to the docs for
WSAStartup:

http://msdn2.microsoft.com/en-us/library/ms742213(VS.85).aspx

From there, you can get to the rest of the documentation. Be sure to
click on the links at the top of the page (WS2, WS Reference, WS
Functions, etc).
So could someone help me?

In general this newsgroup is for questions about the C++ language
itself (e.g. syntax). This is not the place to come for help with
sockets or network programming.
I just need a very simple server and client
without to much of a hassle or frustration!

Read Beej's guide, linked above.
I don't need anything big
like couple Gs. Only a couple megabytes for a file. I only want a
something that one person puts a file on, and another person downloads
it.

But you should question whether or not you are ready to undertake this
task. Here are some other options, in addition to the above:

1) Go find and download a free FTP server and set that up.

2) To send files to people, consider services like sendspace.com.

3) Find another programming language or development environment that
wraps up network programming into something more convenient. For
example, VisualBASIC is great for putting together complex GUI's
quickly, and the Winsock ActiveX control can make things a lot easier.
Or CodeGear RAD Studio (was Borland C++ Builder), is available for a
free 30-day trial from codegear.com, it's all C++ but the Indy
component library that comes with it makes things like embedding FTP
servers in your applications a snap. Java abstracts many network
things, although the concepts are still the same. There are many, many
alternatives here.

I suggest option #1.
Though i'm not sure if i would like multi-thread?!

You need to go through the information I just gave you, first.

Jason
 
C

CAwehking

(e-mail address removed)...


You can use either one you want.


The library you want is called ws2_32.lib. How, specifically, you link
to it depends on the linker and IDE you are using. Most IDE's let you
specify this in the project options or build settings in the linker-
related section. In VS 2005 Express, go to the project properties,
then Configuration Properties -> Linker -> Input and add "ws2_32.lib"
to "Additonal Dependencies". In Dev-C++ it's probably similar, or you
have to add the lib to your project or something. I don't know, check
the docs for your IDE.


The concepts will be the same in many, although not all, of the
programming languages that you would try. Here is a great general
tutorial on socket programming. Read it in its entirety. It is
relatively short, really easy to read, and covers a lot of topics.

http://www.beej.us/guide/bgnet/output/html/singlepage/bgnet.html

For all the Windows-specific stuff, and other general references,
visithttp://msdn.microsoft.com. Here is a link to the docs for
WSAStartup:

http://msdn2.microsoft.com/en-us/library/ms742213(VS.85).aspx

From there, you can get to the rest of the documentation. Be sure to
click on the links at the top of the page (WS2, WS Reference, WS
Functions, etc).


In general this newsgroup is for questions about the C++ language
itself (e.g. syntax). This is not the place to come for help with
sockets or network programming.


Read Beej's guide, linked above.


But you should question whether or not you are ready to undertake this
task. Here are some other options, in addition to the above:

1) Go find and download a free FTP server and set that up.

2) To send files to people, consider services like sendspace.com.

3) Find another programming language or development environment that
wraps up network programming into something more convenient. For
example, VisualBASIC is great for putting together complex GUI's
quickly, and the Winsock ActiveX control can make things a lot easier.
Or CodeGear RAD Studio (was Borland C++ Builder), is available for a
free 30-day trial from codegear.com, it's all C++ but the Indy
component library that comes with it makes things like embedding FTP
servers in your applications a snap. Java abstracts many network
things, although the concepts are still the same. There are many, many
alternatives here.

I suggest option #1.


You need to go through the information I just gave you, first.

Jason

Thanks for the guide, though theres one problem... I wanted something
in C++, and the file name was server.c & client.c. Wouldn't i need
something like server.cpp and client.cpp?
 
J

jason.cipriani

Thanks for the guide, though theres one problem... I wanted something
in C++, and the file name was server.c & client.c. Wouldn't i need
something like server.cpp and client.cpp?

Visual Studio and Dev-C++ will compile both C++ and C source files...
they just look at the file extension...

Also, while C++ isn't completely backward compatible with C (for
example, you could have a variable named "class" in C but in C++ it's
a special keyword, that's not the only difference), I see nothing in
the examples there that need to be changed (or that would be too
difficult to change) to compile those with a C++ compiler -- if you
really had to.

But... those examples aren't going to compile with Visual Studio as-is
anyway. Make sure you read the "Notes for Windows Programmers" section
(1.5) and take a glance at the WinSock FAQ linked there.

Jason
 
J

jason.cipriani

Thanks for the guide, though theres one problem... I wanted something
in C++, and the file name was server.c & client.c. Wouldn't i need
something like server.cpp and client.cpp?

Visual Studio and Dev-C++ will compile both C++ and C source files...
they just look at the file extension...

Also, while C++ isn't completely backward compatible with C (for
example, you could have a variable named "class" in C but in C++ it's
a special keyword, that's not the only difference), I see nothing in
the examples there that need to be changed (or that would be too
difficult to change) to compile those with a C++ compiler -- if you
really had to.

But... those examples aren't going to compile with Visual Studio as-is
anyway. Make sure you read the "Notes for Windows Programmers" section
(1.5) and take a glance at the WinSock FAQ linked there.

Jason

P.S. Sorry if this is a double post; I had posted it via Google Groups
and while it showed up on the group, I just now realized it did not
show up in the outside world... at least according to Outlook Express.
 
C

CAwehking

Visual Studio and Dev-C++ will compile both C++ and C source files...
they just look at the file extension...

Also, while C++ isn't completely backward compatible with C (for
example, you could have a variable named "class" in C but in C++ it's
a special keyword, that's not the only difference), I see nothing in
the examples there that need to be changed (or that would be too
difficult to change) to compile those with a C++ compiler -- if you
really had to.

But... those examples aren't going to compile with Visual Studio as-is
anyway. Make sure you read the "Notes for Windows Programmers" section
(1.5) and take a glance at the WinSock FAQ linked there.

Jason

P.S. Sorry if this is a double post; I had posted it via Google Groups
and while it showed up on the group, I just now realized it did not
show up in the outside world... at least according to Outlook Express.

Thanks very much for that last post! It's getting me on a roll now!
But yes you did double-post. Though now i see why all those header
files were in there! But I think i'll get VC++. Though one question,
this might seem like some kind of "noob" question. But just C++, there
are many, many, C++ programms. I use dev, though i see things like
"pearl, quarrel, and VC" and much more. But does it really change the
coding language? or just another programm with the exact same
language? They all say there C++.
 
J

jason.cipriani

Thanks very much for that last post! It's getting me on a roll now!

You are welcome. :)
[snip] But just C++, there
are many, many, C++ programms. I use dev, though i see things like
"pearl, quarrel, and VC" and much more. But does it really change the
coding language? or just another programm with the exact same
language? They all say there C++.

I will try to be clear but this is the last thing I'm doing before I
go to bed tonight, and it is getting late. So sorry if I'm incoherent.

C++ is C++. It's a language defined in a 700-ish page ISO (or ANSI or
whatever it is) standard document. Different compilers have their own
sets of bugs and quirks (esp. regarding unclear parts of the standard)
but the language is (ideally) the same.

On the other hand, many compilers have added their own extensions, or
have their own way of doing things that are not defined in the C++
standard. For example, inline assembler syntax will be different from
compiler to compiler. The Microsoft compiler has an "__int64" type.
The Borland compiler has the "__closure" keyword. But those are
features that go beyond what the C++ standard defines.

Same deal with some of the runtime functions. Like socket(), for
example. The BSD socket API (the one described in that tutorial) is
not part of the C++ standard. It is not necessarily true that a given
compiler or platform will ship with a runtime library that uses
"socket()" (for example), or whatever. It is also not necessarily true
that the headers that these kinds of functions are declared in will be
the same from system to system. A good example is multithreading.
POSIX defines pthresds, but the Windows API does not use POSIX
threading, it uses it's own set of functions. None of this stuff is
defined in the C++ standard so a proper C++ compiler and runtime
library doesn't necessarily need to support, say, POSIX thread calls.

So in a nut shell: C++ is C++; it's the stuff that's outside the C++
standard (like sockets, threading, language extensions, various other
things) that will differ between compilers and platforms.

Jason
 
J

jason.cipriani

To clarify something:

On the other hand, many compilers have added their own extensions, or
have their own way of doing things that are not defined in the C++
standard.

That is to say, many compilers have their own way of doing extra
things *beyond* what is defined in the C++ standard without
conflicting (well that's the goal) with the standard. E.g. it's not
like, say, SQL, where the language is roughly similar between
implementations but every database server seems to have it's own
dialect.

It's not really as crazy as it may seem though.
 
C

CAwehking

To clarify something:



That is to say, many compilers have their own way of doing extra
things *beyond* what is defined in the C++ standard without
conflicting (well that's the goal) with the standard. E.g. it's not
like, say, SQL, where the language is roughly similar between
implementations but every database server seems to have it's own
dialect.

It's not really as crazy as it may seem though.

So what your saying is that they all have the same programming
language, but some of them have more codes "possible" than other
programms? Also what is the big difference with Visual C++, and Visual
Basic, or Visual Studio? Because I see some pictures of them with some
sort of diagram, not source code. So, I don't really get the big hint
of that one.
 
J

jason.cipriani

So what your saying is that they all have the same programming
language, but some of them have more codes "possible" than other
programms?

In a nutshell, yes.
Also what is the big difference with Visual C++, and Visual
Basic, or Visual Studio?

Visual C++ is for writing programs in C++. Visual BASIC is for writing
programs in BASIC, which is a different programming language that is
not C++. Visual Studio is just Microsoft's name for the entire
collection of "Visual Whatever" products. If you see somebody say
"Visual Studio" when talking about C++, they are probably talking
about the "Visual C++" part of it only.
 
J

jason.cipriani

So what your saying is that they all have the same programming
language, but some of them have more codes "possible" than other
programms?

In a nutshell, yes.
Also what is the big difference with Visual C++, and Visual
Basic, or Visual Studio?

Visual C++ is for writing programs in C++. Visual BASIC is for writing
programs in BASIC, which is a different programming language that is
not C++. Visual Studio is just Microsoft's name for the entire
collection of "Visual Whatever" products. If you see somebody say
"Visual Studio" when talking about C++, they are probably talking
about the "Visual C++" part of it only.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,178
Messages
2,570,955
Members
47,509
Latest member
Jack116

Latest Threads

Top