|
Hi,
I have a server-client based chat app.
Now I want to implement that you can send files. For that, I created a new data socket on the side of the one who will receive the file. I thought it would be faster not to go through the server, but to have a peer to peer connection for file transfer. But my problem is: How can I tell the other one which IP I have, so that he can connect on it.
When I use getsockname, I get the local IP. For example: Server and Client are running on the same machine. Now, if the server reads the IP of the client who is connected, it get 127.0.0.1, which isnt useful!
So, two questions: How to get the global IP?
Second: Am I to strict, saying that sending a file from one client through server to another client is too slow?!
DKT
|
|
|
|
|
DKT_ wrote:
When I use getsockname, I get the local IP. For example: Server and Client are running on the same machine.
use [getpeername] api
"Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow
cheers,
Alok Gupta
|
|
|
|
|
hello everyone:
Now i have a project based on cformview.There are many forms to be dispalay when needed.In the first form there is a button,and the left forms have other controls such as list ,tree,ets.what i want to do is as below :
Firstly, i want to stop the form being created when the project started,and the first form can be created when neccessary.
Sencondly,when the button in the first form is clicked ,another form is called .
Lastly,the controls in the forms can be rized .
what can i do with it ?Sooooooooooorry for sooooooo many questions. i am confused now,is there any one who can help me ?anything will be appreciated ,thanx in advance!
|
|
|
|
|
|
Thank you so much for your replying ,sir.
can you let me have a look at your SDI sample?Now i am going to write a MDI one.
|
|
|
|
|
|
Thank you so much ,sir.i have solved my problem now.
this sample helps me a lot.But i don't know how to send it to you .i am so sorry.Can you tell me your E_mail?
|
|
|
|
|
Hi,
How to restrict my application to one instance only. I mean to say either we click several time on myappiction.exe, only one myapplication.exe should be run not multiple. I think this is possible to set a value in the registry but how to do?
Any help appreciated.
Regards
Rajesh
rajesh
|
|
|
|
|
|
I would not do it by setting a value in the registry. Imagine this situation:
- Instance1 starts and sets the Value "running=1" in the registry.
- Instance2 starts and reads the value in the registry -> "running=1" -> quit.
- Instance1 exits and resets the value "running=0"
- Instance3 starts. "running=0" -> runs and sets "running=1".
Everything fine for now. But lets go further:
- Instance3 crashes or is killed by a user. Registry key is not reset. "running=1"!!!
- Instance4 starts. checks for registry key -> "running=1" -> quits!!!
So now the application cannot be started again until someone manually resets the registry key. Not nice!
Better solutions:
use a named mutexenumerate all running processes and look if your's is already runningSearch for something like Single Instance Application VC++ or Singletion Application VC++ here on CodeProject or on Google and you'll find several examples how to solve this.
Claudio
Claudio's Website
Hommingberger Gepardenforelle
|
|
|
|
|
You mean doing something like this
TCHAR Buff[255];
HANDLE hMutexOneInstance= CreateMutex(NULL,TRUE,_T("PreventSecondInstance"));
GetPrivateProfileString(_T("INSTANCE"),_T("DESIGNCLASS"),_T(""),Buff,79,_T("MYAPP.INI"));
HWND Wnd = ::FindWindow (Buff,NULL);
if (Wnd) {
::SetFocus(Wnd);
::ShowWindow(Wnd,SW_SHOWMAXIMIZED);
}
if(hMutexOneInstance)
ReleaseMutex(hMutexOneInstance);
And if No Instance is already running. Write this to ini file. Obviously registry can be used for this as well.
GetClassName(m_pMainWnd->m_hWnd,Buff,80);
WritePrivateProfileString(_T("INSTANCE"),_T("DESIGNCLASS"),Buff,_T("MYAPP.INI"));
And yes, do it in InitInstance Method.
"I would luv to change the world, but they wont give me the source code"
My Articles
|
|
|
|
|
No, I don't mean something like this (well to be honest, I don't see from your example what your writing to the ini file). Because in this situation you still have the same problem: who deletes the information in the ini-file or in the registry, when your application crashes? After a crash, your information of "application is running" stays in the ini-file/registry forever and you won't be able to start your app again because it still thinks it is running.
The idea with the mutex is the following:
When you start your application, you first create a named mutex using something like CreateMutex(null, true, "anyuniquestring"); . If this succeeds you get a handle to the mutex. Then you call GetLastError . If your application is not already running (so it's the first instance creating the named mutex) it will not return an error. But if there is already an instance running GetLastError will return ERROR_ALREADY_EXISTS . So this way you know, there is already an instance of your application running.
Claudio
Claudio's Website
Hommingberger Gepardenforelle
|
|
|
|
|
Sorry, I didnt describe it in detail. I just picked this code from one of my projects and pasted it here without much editing. In that application, I am writing the clsid (which is unique for my app) in the ini file.
You are right though, mutex can be used in a better way as u described.
"I would luv to change the world, but they wont give me the source code"
My Articles
|
|
|
|
|
See here.
"Ideas are a dime a dozen. People who put them into action are priceless." - Unknown
|
|
|
|
|
|
Hi everybody,
I have created an PopUp Menu in a CDialog...it works OK.
Now I want to create a PopUp Menu inside an ActiveX every time I click Button RIGHT of the mouse...
I have copied the code inside the function WM_RBUTTONDOWN...The problem is that it shows the Menu but it is DISABLED (it is shown but I can not select an option).
How can I do it to solve it...to make it enable?Someone has told me that it doesn't work 'cause I need to call a function for each Item of the Menu...but
Thanks
Here the code :
HMENU hMenu = ::CreatePopupMenu();
if (NULL != hMenu)
{
// add a few test items
::AppendMenu(hMenu, MF_ENABLED | MF_STRING , 1, "Change Color");
::AppendMenu(hMenu, MF_ENABLED | MF_STRING , 2, "Hide");
::AppendMenu(hMenu, MF_ENABLED | MF_STRING , 3, "Item 3-");
ClientToScreen(&point);
int sel = ::TrackPopupMenuEx(hMenu,
TPM_CENTERALIGN | TPM_RETURNCMD,
point.x,
point.y,
m_hWnd,
NULL);
CString s;
s.Format("The selected item is %d", sel);
TRACE(s);
::DestroyMenu(hMenu);
|
|
|
|
|
create a menu in your ressources
create a wm_command message handler for your menu items with the class wizard
alternatively, you can handle the wm_contextmenu message:
void CCtrl::OnContextMenu(CWnd* pWnd, CPoint point)
{
CMenu menu;
CMenu* submenu;
menu.LoadMenu(IDR_POPUPMENU);
submenu = menu.GetSubMenu(0);
submenu->TrackPopupMenu(TPM_LEFTALIGN|TPM_RIGHTBUTTON, point.x, point.y, pWnd);
}
that's it
thomas
|
|
|
|
|
I have a problem with multiple tcp (http) connections on Windows. When my program sent many (says, 300 http-connections. The critical number of http-connections depends on speed of Internet connection) http-requests, part of them are stuck. That means, request is sent, but response is either received partly or not received at all. At that, a stuck connection isn’t dropped by web server.
This problem is present only in the Internet. There is no such problem on local machine. Based on experiment, the problem doesn’t depend on either my application sends all 300 requests to single web server or my app sends requests, says, to 6 servers by 50 requests to each server. The result is the same: some of connections are stuck for a long time.
I made a small program to investigate this problem. The program sends http-requests and receives http-response. The program creates the thread for each connection. There is opportunity to set timeout between creating connections. By default, there is no timeout and all connections are created at the same time. When I was playing with this app, I found that if I set the timeout (10-100 millisecond), http-requests worked more effectively. Sometimes, if to choose the right timeout, there are no stuck and the app uses almost all available bandwidth.
Can somebody write what’s the problem? Why are requests are stuck? What’s the cause? I could send the test app with source codes (c++) by request.
Thanks!
--
Vadim
|
|
|
|
|
The HTTP protocol requires that a client has no more than 2 open connections to the same server. Windows enforces this at the API level. There are registry entries you can change to modify this behavior. See this[^] link.
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
I'm sorry for the late response.
I don't use WinInet API. I use Windows Sockets, no such limitations should be there. Plus all is working perfectly with local web server. There is the problem only through Internet.
|
|
|
|
|
meremortal wrote:
I use Windows Sockets, no such limitations should be there.
Have you confirmed this by modifying the registry settings?
/ravi
My new year's resolution: 2048 x 1536
Home | Articles | Freeware | Music
ravib@ravib.com
|
|
|
|
|
|
No. I'm using Win2k and all requests are sending to valid IP addresses.
|
|
|
|
|
Well it doesn't matter if it is to valid or invalid address. But anyway, you don't use XP
Because as you said, if used locally it works perfectly, I would say that there will be a problem in IP stack - either on your machine or on the peer - if you open hundreds of connections simultaneously, it can have reach some SYN flood protection on the peer side or something like that. I think some tool like TCPView from sysinternals can help revealing what's up.
Anyway what's the ping time between the machines?
|
|
|
|
|
I am trying to build a Java launcher for a Java Product. Executing a Java application with a Batch file looks akward. I want a write code so that a native application written in VC++ can launch the Java application. The batch file of the application looks like this
---------------------------------------------------------------------------------------------------
set path=%PATH%;.\java\j2re1.4.2_07\bin;.\java\j2re1.4.2_07\lib;.\JMF2.1.1e\bin;
set classpath=.\JMF2.1.1e\lib\sound.jar;.\JMF2.1.1e\lib\jmf.jar;
java -classpath Sample.jar;%CLASSPATH%;%JMFHOME% -Djava.library.path=./Samplelib NrthSample.SampleMainApplication
---------------------------------------------------------------------------------------------------
Is there any way to lauch the Java application straight for the native application without the batch file? Can someone tell me which functions to use??
Regards.
|
|
|
|
|