|
-
Sep 6th, 2001, 09:45 PM
#1
Thread Starter
New Member
Creating a server using MFC
I am wanting to create a server side program that will create a socket using CSocket, and listen on that port continuely until a client program calls and connects to that port from a remote location. I have the client up and running, it will already go and look for that port, but the problem with the server is, it opens the port and then closes the port right afterwards. Here is an example of what I got:
Keep in mind I am using Dialog boxes not SDI or MDI
CForm::IDConnect()
{
UpdateData();
CSocket Server;
Server.Create(m_Port);
if (Server.Listen())
...
}
That is the main Idea of my program for the server, however I am not quite sure what to put after the if...
Can anyone Help?
Thankx in advance.
-
Sep 7th, 2001, 05:52 AM
#2
I'd create a thread that communicates with the client and then let the main thread return to listening status. But I don't know this things really, so I can't give you any code.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
-
Jan 8th, 2002, 01:02 AM
#3
Server.Create(m_Port);
I have a question:
After this line
Server.Create(m_Port);
Shouldn't I be able to get the host of this server socket?
I use
sockSrvr->GetSockName( rSocketAddress, rSocketPort );
where
sockSrvr is a CSocket* instead of your Server CSocket
How do you get the local IP for the server?
ipconfig (in DOS shell) reports that I have 3 ethernet adapters and 1 of them is the local IP I need.
VB's Winsock control reports the IP I need after a Listen.
Java reports the IP I need after creating a ServerSocket.
Hmmm, maybe I need to chack after a Listen. But anyway
rSocketAddress is always 0.0.0.0
Actually I was checking after the Listen - edit
Or how do I get my local IP so that I can explicitly create a socket with that host IP?
I'd like to know the MFC technique to obtain my local IP (to know what to post as my server address to a public directory).
I am interested in any C or C++ technique to determine this.
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
|