Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Networking in VC++ 6.0

Status
Not open for further replies.

Foxx

Programmer
Jan 31, 2001
7
US
Hello, its me again with another strange question. I've been taught a decent amount of regular C++ and trying to move into Visual. Its difficult without having the college teach Visual but this is how I'm trying to manage. For a program I'm trying to write it is supposed to have an interface similar to a chat room where the users connected to the server can interact. When certain key words are typed in the middle of sentences like "/slash" it sends the server a signal to start executing the rule system, pulling data from each of the clients' character data programs (somewhat seperate but still integrated into this). However, while I think I can manage with learning enough VC++ to manage the interface for the user manipulating all the aspects of the character sheet, I need a few references to try and learn about networking and the interfaces available in VC++ across the internet. More specifically, I need to know about how to have one computer set up as a server and have it able to control the clients connected to it with certain limits imposed (no direct manipulation of charcter data, etc.) but still being able to monitor those aspects of their character sheets. Any help with references, suggetsions on books are appreciated. Thank you.
 
Foxx,
Inorder to achieve your task, you have following options:

1) Use CSocket class, (MFC)
2) Use CAsyncSocket Class (MFC)
3) Use socket programming. (Raw socket programming)

The first two choices involve using MFC's built in classes. For more help on these just explore MSDN CD(the on-line help system for Visual C++) and search for these classes. You will get all the help that you need, from these help files. Don't forget to check out the sample programme that comes with Visual C++ named CHATTER. This programme ,fortunately for you, does exactally what you intend to do. Its a chat server and a chat client. The server maintains multiple connection to clients -- exactally what you intend to do in your project/application.

Personally i like working with sockets directly. This is because the programme made by using socket programming, would run on LINUX/UNIX and Windows, without any considerable change. Any also the socket programming give you much more control and is extremely easy to learn. Below is the sequence of function that you will need to use for the server and the client application:
============
Client
===========

struct sockaddr_in a;
WSADATA wsaData;


WSAStartup(0x101, &wsaData);

a.sin_family = AF_INET;
a.sin_port = htons(SERVER_PORT_NO);
a.sin_addr.s_addr = inet_addr(strServerAddress);

s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
connect(s, (struct sockaddr *)&a, sizeof(a)))
send(s,"OK",strlen("OK"),0); // Will send "OK" to server

// Will receive the data from the server in the "buffer"
recv(s,buffer,length_of_buffer,0);
// Do clean up
closesocket(s);
WSACleanup();

======
Server
======
socket()
bind()
listen()
while (1)
{// The server will run forever.
accept()
send()
recv()
closesocket()
}
WSACleanup();

====================
The potential problblem with using socket programming is
that the send()/recv() are blocking functions, so if the server is not sending anything then the client will block at recv(). To counter this you will have to use Windows multi threading.

Anyway the choice is yours, as to how you choose to implement your project. To run your application you will need winsock.dll and wsock32.dll. And ofcourse a hosts file in your windows directory with the appropriate IP addresses or a live connection to the LAN/internet where a DNS may be contacted to resolve IP addresses.

Hope the info was useful,
cheers
Kashif



When the going gets tough; the tough gets going; and the toughest of all sleeps zzzZZZ
 
Hey guys...


I Wann'a Some Nice code about Winsock executing with win32

Operating system! if do not .... any kind of Souce accepted

like MFC Socket program source

please help me....

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top