First of all I want to apologise both for my English and for probably elementary questions.
I need to create a GUI for a client to connect to another application that works as a server and uses TCP/IP protocol.
I've already created a GUI that can access to server and send the messages (I've used winsock.h). It works only for the first "click".
I need some buttons with pre-setted instructions to send so I've written the same code in every button, changing only the message to send. Is that wrong for connection? I initialize and connec to socket in every button.
I post the piece of code:
Code: Select all
void Project1Frm::WxButton1Click(wxCommandEvent& event)
{
WORD wVersionRequested = MAKEWORD(2,2);
WSADATA wsaData;
WSAStartup(wVersionRequested, &wsaData);
SOCKET sock;
sock=socket(AF_INET, SOCK_STREAM, 0);
SOCKADDR_IN addr;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
addr.sin_port = htons(port);
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr));
wxString mess;
mess="start#1#end";
send(sock,mess,strlen(mess),0);
}
/*
* WxButton2Click
*/
void Project1Frm::WxButton2Click(wxCommandEvent& event)
{
WORD wVersionRequested = MAKEWORD(2,2);
WSADATA wsaData;
WSAStartup(wVersionRequested, &wsaData);
SOCKET sock;
SOCKADDR_IN addr;
short port;
port = 10501;
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
addr.sin_port = htons(port);
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
connect(sock, (struct sockaddr*)&addr, sizeof(struct sockaddr));
wxString mess;
mess="stop#2#end";;
send(sock,mess,strlen(mess),0);
}
I apologise again but I need it for thesis also if I'm a mechanical engineer and I've never seen a client server application before (if that is possilble).
Cheers,
Francesco
[/code]