Client GUI

This forum is reserved for everything you want to talk about. It could be about programming, opinions, open source programs, development in general, or just cool stuff to share!
Post Reply
fdf86
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Jul 27, 2010 3:38 pm
Location: Italy

Client GUI

Post by fdf86 »

Hi,
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 didn't close the socket and free the libreries because I thougth doing it in another button.
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]
fdf86
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Jul 27, 2010 3:38 pm
Location: Italy

Post by fdf86 »

I solved instantiating SOCKET in projectFrame.h (section private) so I don't need to reinitialize the socket..
thanks anyway!
Post Reply