I have been doing socket programming lately. I then tried to implement it on Visual C++. I encountered a few problems. I will post the codes first.
Form1.h
Code:
#include <string>
public:
char* str;
System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
String^ temp = textBox1->Text;
MarshalString(str, temp); //convert String^(temp) to char*(str)
if ((result2 = send(sockfd, str, strlen(str), 0)) == -1) //flags are left to 0
{
printf("Send failed: %d\n", result2);
exit(1);
}
Server.cpp
Code:
#include "stdafx.h"
#include "Form1.h"
#include <windows.h>
#include <winsock2.h>
if ((result2 = send(sockfd, msg, strlen(msg), 0)) == -1) //flags are left to 0
{
printf("Send failed: %d\n", result2);
return 1;
}
Note that i have excluded irrelevant code. Here are my Form1.h and Server.cpp. I have a textbox, "textBox1" which i will trype something in it before i click "button1" to send something to the client. However, i do not know how to listen on the event button1_Click in Server.cpp
Here is my pseudocode of what i wish to do.
Code:
listen for button1 click event
if button is click
get the message from the textbox1 and store it into the str variable
initiate send