Ir para conteúdo
Fórum Script Brasil
  • 0

Sockets


piteri

Pergunta

5 respostass a esta questão

Posts Recomendados

  • 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 para o comentário
Compartilhar em outros 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 para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...