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