--- trunk/Client/ClientDlg.cpp 2007/01/30 08:03:08 15 +++ trunk/Client/ClientDlg.cpp 2007/01/30 13:44:42 16 @@ -11,8 +11,14 @@ #endif -CString Ip; +CString Ip, Delay; unsigned long Port; +UINT Status( LPVOID Param ); +void Start(); +void startthread(); +CButton m_led1; +CButton m_led2; +CButton m_led3; // CAboutDlg dialog used for App About @@ -66,6 +72,7 @@ DDX_Control(pDX, IDC_POT, m_pot); DDX_Control(pDX, IDC_IPADDRESS1, m_ip); DDX_Control(pDX, IDC_PORT, m_port); + DDX_Control(pDX, IDC_DELAY, m_delay); } BEGIN_MESSAGE_MAP(CClientDlg, CDialog) @@ -85,7 +92,6 @@ ClientSocket() { }; virtual void OnReceive(int nErrorCode); virtual void OnSend(int nErrorCode); - virtual void OnConnect(int nErrorCode); }; BOOL CClientDlg::OnInitDialog() { @@ -119,6 +125,7 @@ // Get data from regedit CString strip, strport; char chaip[16]; + char chadelay[16]; CRegKey reg; unsigned long size = 16; LONG res=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ); @@ -137,10 +144,20 @@ } strport.Format("%d",Port); m_port.SetWindowText(strport); + + LONG res3=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ); + + if (res3 == ERROR_SUCCESS) + { + res3=reg.QueryStringValue("Delay",chadelay,&size); + } + Delay = chadelay; + m_delay.SetWindowText(Delay); reg.Close(); //connect til server - + Start(); + return TRUE; // return TRUE unless you set the focus to a control } @@ -201,17 +218,34 @@ /*Clientsocket class used for client socket connections*/ void ClientSocket::OnReceive( int nErrorCode ) { - CString ip; - UINT port; char buffer[4096]; - CString str; int size; + CString buff; - str.Format("%s %d",ip,port,""); size = Receive(buffer,4095); buffer[size] = 0; -// Recivetekst = buffer; recivetekst er der ikke endnu - //Send(str,str.GetLength()); vi skal ikke sende endnu + MessageBox(0,buffer,0,MB_OK); + buff = buffer; + if( buff == "Tændt" ) + { + char test[10]; + int i; + i = m_led1.GetCheck(); +// _itot(i,test,10); Fejltjeck +// MessageBox(0,test,0,MB_OK); + if(i == 0) + { + m_led1.SetCheck(1); + } + else + { + m_led1.SetCheck(0); + } + } + else + { + MessageBox(0,"FEJL i onrecive",0,MB_OK); + } Close(); } void ClientSocket::OnSend( int nErrorCode ) @@ -227,6 +261,11 @@ //Set new port and ip for the server in regedit m_ip.GetWindowText(strIp); m_port.GetWindowText(strPort); + m_delay.GetWindowText(Delay); + int test; + test = atoi(Delay); + if(test < 10000 && test > 100) + { CRegKey reg; reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client"); reg.SetStringValue("","Project-data"); @@ -234,26 +273,46 @@ reg.SetStringValue("IP",strIp); reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client"); reg.SetDWORDValue("Port",atoi(strPort)); + reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client"); + reg.SetStringValue("Delay",Delay); reg.Close(); + } + else + { + MessageBox("fejl i delay",0,MB_OK); + } } -void ClientSocket::OnConnect(int nErrorCode) -{ - // TODO: Add your specialized code here and/or call the base class - strPort.Format("%d",strPort); - sockClient.Connect(strIp,Port); - sockClient.Send(strPort,strPort.GetLength(),0); - sockClient.Close(); - CSocket::OnConnect(nErrorCode); -} void Start() { - strPort.Format("%d",Port); - sockClient.Connect(Ip,Port); - sockClient.Send(strPort,strPort.GetLength(),NULL); - sockClient.Close(); + sockClient.Create(); + if (sockClient.Connect(Ip,Port)) + { + //sockClient.Send(strPort,strPort.GetLength(),NULL); + //sockClient.Send(data,data.GetLength(),NULL); + //sockClient.Close(); + } + else + { + int error = GetLastError(); + CString tmp; + tmp.Format("%d", error); + } } void CClientDlg::OnBnClickedConnect() +{ + +} +UINT Status( LPVOID Param ) { - Start(); + CString status; + status = "RB1"; + Sleep(atoi(Delay)); + sockClient.Send(status,status.GetLength(),NULL); + startthread(); + return TRUE; } +void startthread() +{ + AfxBeginThread(Status,0,THREAD_PRIORITY_NORMAL,0,0,NULL); +} \ No newline at end of file