Re: How to write a simple multithreading application with WinSock

Tech-Archive recommends: Fix windows errors by optimizing your registry



Dear Gershnik,
Thanks for the support. Would you please clarify the FAR word attached to
some of the data type of C/C++ that I found it in the book that you mentioned
to me, for example:

char FAR *cp
u_short FAR *lphostshort
u_long FAR *lphostlong

As you can see there is always the repeated word "FAR" that i have not met
before.
I would be thankfule for your help.

Regards
Bassam


"Eugene Gershnik" wrote:

Bassam wrote:
I scaned the both mentioned great books and it seems that I need a
long time to learn on how to build server services, multithreading
and use Winsock with them.

Yup.

However, I skimmed the first chapter
"Introduction to Winsock" of the book "Network Programming for
Microsoft Windows - 2nd Edition" and I tried to write a very simple
program using "Visual C++ 2005 Express Edition" as follow:

#include <IOSTREAM>

This should be #include <iostream>. You come from a case-sensitive OS
doesn't you ;-)

[...]

So whenever I compile (Build Solution) the program, I get this error:
"fatal error C1083: Cannot open include file: 'winsock2.h': No such
file or directory"
the same error I get when I use winsock.h rather than winsock2.h.

You need to download and install Windows SDK that contains headers and
libraries for Windows API (system calls). Unlike Unix, Windows doesn't come
with these libraries pre-packaged and compiler pre-configured to find them.
After you install the SDK make sure your compiler can find its include and
lib paths (look under Tools/Options/Projects and Solutions on VC8 and
something similar on previous versions)

It seems to me that the winsock.h and winsock2.h are not parts of the
C++ standard library and they need to be included.

Yes.

One more inquiry, all the sample programs in this book are written in
C language (Correct me if I am mistaken),

You are correct. Similar to Unix the system language of Windows is C so any
book that discusses system facilities will most likely use C.

I wonder if there is a
reference that uses C++ in winsock rather than C. I don't know if the
code is the same for both C and C++.

It depends on what you mean by C++ in this context. In general on Windows
most people compile C using C++ compiler so the samples you are likely to
encounter will probably already be C++ compatible.
If you are looking for nice class libraries that wrap Winsock functionality
there are none that I would recommend. (There are plenty of libraries you
can find on Google but they are either huge frameworks or not very usable
"look I can write a socket class" ones)

In order to handle and process multiple requests coming form multiple
clients at the same time in my project, in Unix/Linux OS I used to
write a multithreading socket programming application. Do I need to
do the same thing for windows OS and write a multithreading
application to handle these requests or the it will be handled
internally by winsock?

This is explained in the book you are reading.

--
Eugene
http://www.gershnik.com



.



Relevant Pages

  • Re: DFPORT
    ... I work on a Windows XP platform. ... We normally use F77 Fortran and for this one problematic program we ... Since we also have the Intel Fortran compiler, we also had a lot of ... Windows Fortran comper (with appropriate libraries). ...
    (comp.lang.fortran)
  • Re: How to write a simple multithreading application with WinSock
    ... and use Winsock with them. ... Microsoft Windows - 2nd Edition" and I tried to write a very simple ... with these libraries pre-packaged and compiler pre-configured to find them. ... write a multithreading socket programming application. ...
    (microsoft.public.win32.programmer.networks)
  • Re: Could someone point me to a how-to page...
    ... If you're a Windows user (which I'm willing to bet ... There's a ton of info on curses, ... > ASCII libraries to use. ... my compiler said it was corrupt ...
    (rec.games.roguelike.development)
  • Re: Micro Focus COBOL Visual C++ linking
    ... What Winsock library should I use? ... This is a 16 bit compiler for DOS and Windows 3.x. ...
    (comp.lang.cobol)
  • Re: Win32 Native API
    ... > the normal system functions in any of the versions of Windows. ... you could probably do what you had in mind but particularly ... > when you have a compiler in mind, ... few libraries as I can, as low-leveled as it gets in Windows. ...
    (comp.lang.asm.x86)