-
August 7th, 2001, 07:52 AM
#1
Socket Programming
Hi Friends,
I'm new to socket programming.Can any one help me on how to use CSocket.
thanking in advance
Ramanand
-
August 7th, 2001, 08:13 AM
#2
Re: Socket Programming
Hello, I'm pretty much a beginner too. However, I've been using CSockets for several months now so maybe I can help.
Are you creating a Client and a server or just one?
In the simplest Client Server model, you must use 3 instances of CSocket. 2 of these CSockets are on the server side. The first on the server is a socket used for accepting calls, and should be created on a specific port (so clients know how to find it):
CSocket sockAcptr.Create(iPort);
sockAcptr.Listen();
The sockAcptr listens for connection attempts, and will receive a message when it is able to accept a socket. When this happens, the sockAcptr should accept the call and attach it to the second server socket.
sockAcptr.Accept(socksrvr);
Now, all communication between the server and client goes through the socksrvr not the sockAcptr.
The client socket is created on a default port, you dont have to specify:
CSocket sockclient.Create();
sockclient.Connect(sAddress, iPort);
Connect to the server specifying the server IP address (can be in CString form) and the port the sockAcptr is listening on.
To send information back and forth, I always use CSocketFiles with CArchives.
Create a socketfile bound to the socket that will be sending (or receiving):
CSocketFile file(pSock);
Create an archive bound to the file either for sending or receiving:
CArchive ar(&file, CArchive::store); OR CArchive ar(&file, CArchive::load);
then you can use the archive to send and receive info;
ar << sinfo;
ar >> sinfo;
Let me know if it helps or if you have anymore questions. you may want to double check MSDN to make sure i have the parameters in the right order on some methods.
-
April 4th, 2005, 07:40 AM
#3
Re: Socket Programming
Hello
I am also in need of socket programming..i want to do a program which can communicate with two systems using their IP address. and i am new to this socket programming..Could you please help me in this regard..It would be appreciated if you can send any sample program..
Thanks in advance.
Poornima.
-
April 4th, 2005, 08:31 AM
#4
-
April 4th, 2005, 08:33 AM
#5
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|