10 |
#define new DEBUG_NEW |
#define new DEBUG_NEW |
11 |
#endif |
#endif |
12 |
|
|
13 |
|
|
14 |
|
CString Ip; |
15 |
|
unsigned long Port; |
16 |
|
|
17 |
// CAboutDlg dialog used for App About |
// CAboutDlg dialog used for App About |
18 |
|
|
48 |
// CClientDlg dialog |
// CClientDlg dialog |
49 |
|
|
50 |
|
|
|
|
|
51 |
CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/) |
CClientDlg::CClientDlg(CWnd* pParent /*=NULL*/) |
52 |
: CDialog(CClientDlg::IDD, pParent) |
: CDialog(CClientDlg::IDD, pParent) |
53 |
{ |
{ |
74 |
ON_WM_QUERYDRAGICON() |
ON_WM_QUERYDRAGICON() |
75 |
//}}AFX_MSG_MAP |
//}}AFX_MSG_MAP |
76 |
ON_BN_CLICKED(IDC_IPPORT, OnBnClickedIpport) |
ON_BN_CLICKED(IDC_IPPORT, OnBnClickedIpport) |
77 |
|
ON_BN_CLICKED(IDC_Connect, OnBnClickedConnect) |
78 |
END_MESSAGE_MAP() |
END_MESSAGE_MAP() |
79 |
|
|
80 |
|
|
81 |
// CClientDlg message handlers |
// CClientDlg message handlers |
82 |
|
/*Client socket class*/ |
83 |
|
class ClientSocket : public CSocket{ |
84 |
|
public: |
85 |
|
ClientSocket() { }; |
86 |
|
virtual void OnReceive(int nErrorCode); |
87 |
|
virtual void OnSend(int nErrorCode); |
88 |
|
virtual void OnConnect(int nErrorCode); |
89 |
|
}; |
90 |
BOOL CClientDlg::OnInitDialog() |
BOOL CClientDlg::OnInitDialog() |
91 |
{ |
{ |
92 |
CDialog::OnInitDialog(); |
CDialog::OnInitDialog(); |
115 |
SetIcon(m_hIcon, FALSE); // Set small icon |
SetIcon(m_hIcon, FALSE); // Set small icon |
116 |
|
|
117 |
// TODO: Add extra initialization here |
// TODO: Add extra initialization here |
118 |
|
|
119 |
|
// Get data from regedit |
120 |
CString strip, strport; |
CString strip, strport; |
121 |
char Ip[16]; |
char chaip[16]; |
|
char Port[6]; |
|
122 |
CRegKey reg; |
CRegKey reg; |
123 |
unsigned long size = 16; |
unsigned long size = 16; |
124 |
LONG res=reg.Open(HKEY_CLASSES_ROOT,"Project",KEY_READ); |
LONG res=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ); |
125 |
|
|
126 |
if (res == ERROR_SUCCESS) |
if (res == ERROR_SUCCESS) |
127 |
{ |
{ |
128 |
res=reg.QueryStringValue("IP", Ip,&size); |
res=reg.QueryStringValue("IP", chaip, &size); |
129 |
} |
} |
130 |
|
Ip = chaip; |
131 |
m_ip.SetWindowText(Ip); |
m_ip.SetWindowText(Ip); |
132 |
LONG res2=reg.Open(HKEY_CLASSES_ROOT,"Project",KEY_READ); |
LONG res2=reg.Open(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client",KEY_READ); |
133 |
|
|
134 |
if (res2 == ERROR_SUCCESS) |
if (res2 == ERROR_SUCCESS) |
135 |
{ |
{ |
136 |
res2=reg.QueryStringValue("Port", Port,&size); |
res2=reg.QueryDWORDValue("Port", Port); |
137 |
} |
} |
138 |
m_port.SetWindowText(Port); |
strport.Format("%d",Port); |
139 |
|
m_port.SetWindowText(strport); |
140 |
reg.Close(); |
reg.Close(); |
141 |
|
|
142 |
|
//connect til server |
143 |
|
|
144 |
|
|
145 |
return TRUE; // return TRUE unless you set the focus to a control |
return TRUE; // return TRUE unless you set the focus to a control |
146 |
} |
} |
195 |
} |
} |
196 |
|
|
197 |
|
|
198 |
|
ClientSocket sockClient; |
199 |
|
CString strIp, strPort; |
200 |
|
|
201 |
|
/*Clientsocket class used for client socket connections*/ |
202 |
|
void ClientSocket::OnReceive( int nErrorCode ) |
203 |
|
{ |
204 |
|
CString ip; |
205 |
|
UINT port; |
206 |
|
char buffer[4096]; |
207 |
|
CString str; |
208 |
|
int size; |
209 |
|
|
210 |
|
str.Format("%s %d",ip,port,""); |
211 |
|
size = Receive(buffer,4095); |
212 |
|
buffer[size] = 0; |
213 |
|
// Recivetekst = buffer; recivetekst er der ikke endnu |
214 |
|
//Send(str,str.GetLength()); vi skal ikke sende endnu |
215 |
|
Close(); |
216 |
|
} |
217 |
|
void ClientSocket::OnSend( int nErrorCode ) |
218 |
|
{ |
219 |
|
// CString sendnu; skal ikke sende nu |
220 |
|
|
221 |
|
// sendnu = Sendtekst; skal ikke sende nu |
222 |
|
|
223 |
|
// Send(sendnu,sendnu.GetLength()); skal ikke sende nu |
224 |
|
} |
225 |
void CClientDlg::OnBnClickedIpport() |
void CClientDlg::OnBnClickedIpport() |
226 |
{ |
{ |
227 |
CString Ip, Port; |
//Set new port and ip for the server in regedit |
228 |
m_ip.GetWindowText(Ip); |
m_ip.GetWindowText(strIp); |
229 |
m_port.GetWindowText(Port); |
m_port.GetWindowText(strPort); |
230 |
CRegKey reg; |
CRegKey reg; |
231 |
reg.Create(HKEY_CLASSES_ROOT, "Project"); |
reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client"); |
232 |
reg.SetStringValue("","Project-data"); |
reg.SetStringValue("","Project-data"); |
233 |
reg.Create(HKEY_CLASSES_ROOT, "Project"); |
reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client"); |
234 |
reg.SetStringValue("IP",Ip); |
reg.SetStringValue("IP",strIp); |
235 |
reg.Create(HKEY_CLASSES_ROOT, "Project"); |
reg.Create(HKEY_LOCAL_MACHINE, "SOFTWARE\\Projekt\\Client"); |
236 |
reg.SetStringValue("Port",Port); |
reg.SetDWORDValue("Port",atoi(strPort)); |
237 |
reg.Close(); |
reg.Close(); |
238 |
} |
} |
239 |
|
|
240 |
|
void ClientSocket::OnConnect(int nErrorCode) |
241 |
|
{ |
242 |
|
// TODO: Add your specialized code here and/or call the base class |
243 |
|
strPort.Format("%d",strPort); |
244 |
|
sockClient.Connect(strIp,Port); |
245 |
|
sockClient.Send(strPort,strPort.GetLength(),0); |
246 |
|
sockClient.Close(); |
247 |
|
CSocket::OnConnect(nErrorCode); |
248 |
|
} |
249 |
|
void Start() |
250 |
|
{ |
251 |
|
strPort.Format("%d",Port); |
252 |
|
sockClient.Connect(Ip,Port); |
253 |
|
sockClient.Send(strPort,strPort.GetLength(),NULL); |
254 |
|
sockClient.Close(); |
255 |
|
} |
256 |
|
void CClientDlg::OnBnClickedConnect() |
257 |
|
{ |
258 |
|
Start(); |
259 |
|
} |