/[H7]/trunk/Client/ClientDlg.cpp
ViewVC logotype

Diff of /trunk/Client/ClientDlg.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 15 by kevin, Mon Jan 29 20:10:02 2007 UTC revision 16 by kevin, Tue Jan 30 13:44:42 2007 UTC
# Line 11  Line 11 
11  #endif  #endif
12    
13                    
14  CString Ip;  CString Ip, Delay;
15  unsigned long Port;  unsigned long Port;
16    UINT Status( LPVOID Param );
17    void Start();
18    void startthread();
19    CButton m_led1;
20    CButton m_led2;
21    CButton m_led3;
22    
23  // CAboutDlg dialog used for App About  // CAboutDlg dialog used for App About
24    
# Line 66  void CClientDlg::DoDataExchange(CDataExc Line 72  void CClientDlg::DoDataExchange(CDataExc
72          DDX_Control(pDX, IDC_POT, m_pot);          DDX_Control(pDX, IDC_POT, m_pot);
73          DDX_Control(pDX, IDC_IPADDRESS1, m_ip);          DDX_Control(pDX, IDC_IPADDRESS1, m_ip);
74          DDX_Control(pDX, IDC_PORT, m_port);          DDX_Control(pDX, IDC_PORT, m_port);
75            DDX_Control(pDX, IDC_DELAY, m_delay);
76  }  }
77    
78  BEGIN_MESSAGE_MAP(CClientDlg, CDialog)  BEGIN_MESSAGE_MAP(CClientDlg, CDialog)
# Line 85  public: Line 92  public:
92          ClientSocket() { };          ClientSocket() { };
93          virtual void OnReceive(int nErrorCode);          virtual void OnReceive(int nErrorCode);
94          virtual void OnSend(int nErrorCode);          virtual void OnSend(int nErrorCode);
         virtual void OnConnect(int nErrorCode);  
95  };  };
96  BOOL CClientDlg::OnInitDialog()  BOOL CClientDlg::OnInitDialog()
97  {  {
# Line 119  BOOL CClientDlg::OnInitDialog() Line 125  BOOL CClientDlg::OnInitDialog()
125          // Get data from regedit          // Get data from regedit
126          CString strip, strport;          CString strip, strport;
127          char chaip[16];          char chaip[16];
128            char chadelay[16];
129          CRegKey reg;          CRegKey reg;
130          unsigned long size = 16;          unsigned long size = 16;
131          LONG res=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ);          LONG res=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ);
# Line 137  BOOL CClientDlg::OnInitDialog() Line 144  BOOL CClientDlg::OnInitDialog()
144          }          }
145          strport.Format("%d",Port);          strport.Format("%d",Port);
146          m_port.SetWindowText(strport);          m_port.SetWindowText(strport);
147    
148            LONG res3=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ);
149    
150            if (res3 == ERROR_SUCCESS)
151            {
152                    res3=reg.QueryStringValue("Delay",chadelay,&size);
153            }
154            Delay = chadelay;
155            m_delay.SetWindowText(Delay);
156          reg.Close();          reg.Close();
157                    
158          //connect til server          //connect til server
159            Start();
160            
161                                    
162          return TRUE;  // return TRUE  unless you set the focus to a control          return TRUE;  // return TRUE  unless you set the focus to a control
163  }  }
# Line 201  CString strIp, strPort; Line 218  CString strIp, strPort;
218  /*Clientsocket class used for client socket connections*/  /*Clientsocket class used for client socket connections*/
219  void ClientSocket::OnReceive( int nErrorCode )  void ClientSocket::OnReceive( int nErrorCode )
220  {  {
         CString ip;  
         UINT port;  
221          char buffer[4096];          char buffer[4096];
         CString str;  
222          int size;          int size;
223            CString buff;
224    
         str.Format("%s %d",ip,port,"");  
225          size = Receive(buffer,4095);          size = Receive(buffer,4095);
226          buffer[size] = 0;          buffer[size] = 0;
227  //      Recivetekst = buffer;           recivetekst er der ikke endnu          MessageBox(0,buffer,0,MB_OK);
228          //Send(str,str.GetLength());    vi skal ikke sende endnu          buff = buffer;
229            if( buff == "Tændt" )
230            {
231                    char test[10];
232                    int i;
233                    i = m_led1.GetCheck();
234    //              _itot(i,test,10);               Fejltjeck
235    //              MessageBox(0,test,0,MB_OK);
236                    if(i == 0)
237                    {
238                    m_led1.SetCheck(1);
239                    }
240                    else
241                    {
242                    m_led1.SetCheck(0);
243                    }
244            }
245            else
246            {
247                    MessageBox(0,"FEJL i onrecive",0,MB_OK);
248            }
249          Close();          Close();
250  }  }
251  void ClientSocket::OnSend( int nErrorCode )  void ClientSocket::OnSend( int nErrorCode )
# Line 227  void CClientDlg::OnBnClickedIpport() Line 261  void CClientDlg::OnBnClickedIpport()
261          //Set new port and ip for the server in regedit          //Set new port and ip for the server in regedit
262          m_ip.GetWindowText(strIp);          m_ip.GetWindowText(strIp);
263          m_port.GetWindowText(strPort);          m_port.GetWindowText(strPort);
264            m_delay.GetWindowText(Delay);
265            int test;
266            test = atoi(Delay);
267            if(test < 10000 && test > 100)
268            {
269          CRegKey reg;          CRegKey reg;
270          reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client");          reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client");
271          reg.SetStringValue("","Project-data");          reg.SetStringValue("","Project-data");
# Line 234  void CClientDlg::OnBnClickedIpport() Line 273  void CClientDlg::OnBnClickedIpport()
273          reg.SetStringValue("IP",strIp);          reg.SetStringValue("IP",strIp);
274          reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client");          reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client");
275          reg.SetDWORDValue("Port",atoi(strPort));          reg.SetDWORDValue("Port",atoi(strPort));
276            reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client");
277            reg.SetStringValue("Delay",Delay);
278          reg.Close();          reg.Close();
279            }
280            else
281            {
282                    MessageBox("fejl i delay",0,MB_OK);
283            }
284  }  }
285    
 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);  
 }  
286  void Start()  void Start()
287  {  {
288          strPort.Format("%d",Port);          sockClient.Create();
289          sockClient.Connect(Ip,Port);          if (sockClient.Connect(Ip,Port))
290          sockClient.Send(strPort,strPort.GetLength(),NULL);          {
291          sockClient.Close();                  //sockClient.Send(strPort,strPort.GetLength(),NULL);
292                    //sockClient.Send(data,data.GetLength(),NULL);
293                    //sockClient.Close();
294            }
295            else
296            {
297                    int error = GetLastError();
298                    CString tmp;
299                    tmp.Format("%d", error);
300            }
301  }  }
302  void CClientDlg::OnBnClickedConnect()  void CClientDlg::OnBnClickedConnect()
303    {      
304    
305    }
306    UINT Status( LPVOID Param )
307  {  {
308          Start();          CString status;
309            status = "RB1";
310            Sleep(atoi(Delay));
311            sockClient.Send(status,status.GetLength(),NULL);
312            startthread();
313            return TRUE;
314  }  }
315    void startthread()
316    {
317            AfxBeginThread(Status,0,THREAD_PRIORITY_NORMAL,0,0,NULL);
318    }

Legend:
Removed from v.15  
changed lines
  Added in v.16

  ViewVC Help
Powered by ViewVC 1.1.20