Make a network library from scratch, how to?

Nov 3, 2009 at 10:32pm
Hello there,

First of all, I'd like to say that I'm Brazilian, so sorry if my english is bad.

To the case -> Is it possible to develop/make a network library from scratch with just pure c++ and it's standard library? I DO NOT want to include some Windows API or stuff related to it, just plain old pure c++ and it's standard library. For example, what would I need to make a library that defines a command called Connect(), while it's parameters are somewones IP. Can somewone show me or even do that? Thanks!
Nov 3, 2009 at 11:11pm
You can't.
This is what the interface looks like: bare-bones language (i.e. just syntax and structure. No standard library) -> libraries, including the standard library -> operating system API -> drivers -> firmware -> hardware.
If it's possible, you'd have to at least write your own driver that will handle incoming and outgoing connections and all the other stuff that the OS typically takes care of. Of course, to write the driver you'll have to interface with the OS in one way or another, so you're really just moving the problem.

Really, you'd just be reinventing a huge wheel for no good reason. The OS is there exactly for this kind of stuff: to allocate and manage system resources.
Nov 3, 2009 at 11:29pm
Well, thank you for the response, but, if it's impossible by what I have understood, how did they (somewone) write the standard library, I mean, the windows API AND the c++ Standard Library itself. Thanks
Nov 4, 2009 at 12:09am
The standard library interfaces with the OS API.
The WinAPI is an interface between Windows and the programmer (Application Programming Interface). The function calls make the OS perform different tasks, such as allocating and freeing memory, opening and closing windows, playing sounds, and a very long et cetera. Among these tasks are opening and closing a network connection to a given IP through a given port, and listening for incoming connection on a port. This is all simplified by the OS so you don't have to worry about interfacing directly with the hardware, worry about which network device will the connection go through, and so on. Without the OS, you'd basically have to write a small part of an OS.
And the reason I'm not sure this will work is because I'm not sure the OS will let just any process do whatever the hell it wants with its devices.

Do you have a valid reason to not want to use the system API?
Nov 4, 2009 at 1:24am
To clarify, you do not need to rewrite the underlying OS network functionality. You have to use it whether or not you like it. (Google around "winsock" and "winsock2" for more information.) On Linux/POSIX, you'll need the socket interface http://linux.die.net/man/7/socket

However, if you want a library that makes it easier to do connections, then that is certainly possible.

You might want to take a look at the Tcl socket functionalities. They are the most powerful I've ever encountered.
http://www.tcl.tk/man/tcl8.5/TclCmd/socket.htm

You can download the sources to see how it is done.
http://www.tcl.tk/software/tcltk/download.html
(Be warned, however, that it is advanced code and may take some study.)

Good luck!
Nov 4, 2009 at 11:30pm
Okok!

But then how the hell did they write the WinAPI and the OS??? And about "interfacing directly with the hardware", can that be done in c++, or does it have to be done in some low-level programming language, such as Assembly. I really doubt they designed the whole OS in Assembly or something close to it...

Thanks
Nov 5, 2009 at 1:11am
The relevant parts are written in assembly. Everything else is in C.
Topic archived. No new replies allowed.