piteri Posted November 4, 2004 Report Share Posted November 4, 2004 Ae galera, alguém conhece um bom tutorial que trate de programção em c++ usando sockets? Quote Link to comment Share on other sites More sharing options...
0 iSoron Posted November 5, 2004 Report Share Posted November 5, 2004 Em português:http://www.gazetadolinux.com/pr/lg/issue74/tougher.htmlE em inglês:http://www.ecst.csuchico.edu/~beej/guide/net/html/Divirta-se. Quote Link to comment Share on other sites More sharing options...
0 piteri Posted November 5, 2004 Author Report Share Posted November 5, 2004 Esses seriam pra plataforma Linux ou windows, porque eu to procurando pra windows...valeu Quote Link to comment Share on other sites More sharing options...
0 rodfraga Posted November 5, 2004 Report Share Posted November 5, 2004 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. Quote Link to comment Share on other sites More sharing options...
0 Wicker Man Posted November 5, 2004 Report Share Posted November 5, 2004 Opa!Você precisa de um tutorial da API WinSock. Clique aqui..Até mais! Quote Link to comment Share on other sites More sharing options...
0 iSoron Posted November 6, 2004 Report Share Posted November 6, 2004 Extraído do segundo link que eu passei:1.5. Note for Windows ProgrammersI 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(). Quote Link to comment Share on other sites More sharing options...
Question
piteri
Ae galera, alguém conhece um bom tutorial que trate de programção em c++ usando sockets?
Link to comment
Share on other sites
5 answers to this question
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.