Jump to content
Fórum Script Brasil
  • 0

Sockets


piteri

Question

5 answers to this question

Recommended Posts

  • 0

Esses seriam pra plataforma Linux ou windows, porque eu to procurando pra windows...valeu

Eu acho que o da Gazeta do Linux é pra Linux. Li o segundo em inglês, e o cara diz que os códigos do documento são para Linux. Não sei se em outro lugar ele diz o de Windows.

Procure no google!

Editado: Parece que ele escreve algo para usuários de windows. Leia para ver se lhe interessa.

Link to comment
Share on other sites

  • 0

Extraído do segundo link que eu passei:

1.5. Note for Windows Programmers

I have a particular dislike for Windows, and encourage you to try Linux, BSD, or Unix instead. That being said, you can still use this stuff under Windows.

First, ignore pretty much all of the system header files I mention in here. All you need to include is:

    #include <winsock.h>

Wait! You also have to make a call to WSAStartup() before doing anything else with the sockets library. The code to do that looks something like this:

    #include <winsock.h>

    {

        WSADATA wsaData;  // if this doesn't work

        //WSAData wsaData; // then try this instead

        if (WSAStartup(MAKEWORD(1, 1), &wsaData) != 0) {

            fprintf(stderr, "WSAStartup failed.\n");

            exit(1);

        }

You also have to tell your compiler to link in the Winsock library, usually called wsock32.lib or winsock32.lib or somesuch. Under VC++, this can be done through the Project menu, under Settings.... Click the Link tab, and look for the box titled "Object/library modules". Add "wsock32.lib" to that list.

Or so I hear.

Finally, you need to call WSACleanup() when you're all through with the sockets library. See your online help for details.

Once you do that, the rest of the examples in this tutorial should generally apply, with a few exceptions. For one thing, you can't use close() to close a socket--you need to use closesocket(), instead. Also, select() only works with socket descriptors, not file descriptors (like 0 for stdin).

There is also a socket class that you can use, CSocket. Check your compilers help pages for more information.

To get more information about Winsock, read the Winsock FAQ and go from there.

Finally, I hear that Windows has no fork() system call which is, unfortunately, used in some of my examples. Maybe you have to link in a POSIX library or something to get it to work, or you can use CreateProcess() instead. fork() takes no arguments, and CreateProcess() takes about 48 billion arguments. If you're not up to that, the CreateThread() is a little easier to digest...unfortunately a discussion about multithreading is beyond the scope of this document. I can only talk about so much, you know!

Fora isso aí, é praticamente tudo igual.

O problema que pode dar é com as funções select() ou fork().

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...