help with a TCP Program that sends messages
-
Hi all, New to programming, writing my first app using TCP. I need to make a client server that will send messages to a server. Right now i have two dialog windows. One that takes in the IP that the user wants to connect to(Connection), and another window where the user will set the information that will be sent (Format_Msg). I would like to have a third window that tells me what is sent over and what it receives. I can get the app to connect to the server, I just can not send the appropriate messages over to the server. I do all the connecting and instantiate a socket called ConnectServer in the Connection class. I do all the formatting of the message in the Format_Msg class. my question is how do I send these messages now? I am trying to use the:
send (SOCKET s, const char FAR * buf, int len, int flags)
command but don't know what I am doing wrong. Can I use the same connection that I made (ConnectServer), or do I have to instantiate a socket in the Format_Msg class too? If I don't, could you please tell me how I could get it to recognize the other socket that was instantiated in the Connection class? If you have code to how i could do this, it would be great. Many thanks in advance. -
Hi all, New to programming, writing my first app using TCP. I need to make a client server that will send messages to a server. Right now i have two dialog windows. One that takes in the IP that the user wants to connect to(Connection), and another window where the user will set the information that will be sent (Format_Msg). I would like to have a third window that tells me what is sent over and what it receives. I can get the app to connect to the server, I just can not send the appropriate messages over to the server. I do all the connecting and instantiate a socket called ConnectServer in the Connection class. I do all the formatting of the message in the Format_Msg class. my question is how do I send these messages now? I am trying to use the:
send (SOCKET s, const char FAR * buf, int len, int flags)
command but don't know what I am doing wrong. Can I use the same connection that I made (ConnectServer), or do I have to instantiate a socket in the Format_Msg class too? If I don't, could you please tell me how I could get it to recognize the other socket that was instantiated in the Connection class? If you have code to how i could do this, it would be great. Many thanks in advance.read Nishant S's articles here: http://www.codeproject.com/internet/[^] Don't try it, just do it! ;-)
-
read Nishant S's articles here: http://www.codeproject.com/internet/[^] Don't try it, just do it! ;-)
Hi, I read those articles, thats how i got the app to connect to the server. :-) I am still having problems sending the information though. I don't know if I should be passing in the same connection or instantiating a new one in the second class. Don't know how to use the same connection actually. Can anyone help me with that? Thanks in advance.
-
Hi, I read those articles, thats how i got the app to connect to the server. :-) I am still having problems sending the information though. I don't know if I should be passing in the same connection or instantiating a new one in the second class. Don't know how to use the same connection actually. Can anyone help me with that? Thanks in advance.
you mean you've opened a tcp connection to a server and want to send data through? easy...
send( tcpsocket, buffer, len, 0 );
Don't try it, just do it! ;-) -
you mean you've opened a tcp connection to a server and want to send data through? easy...
send( tcpsocket, buffer, len, 0 );
Don't try it, just do it! ;-)yes that is what i want to do. Only thing is that I create the socket in one class and want to format a message before I send it, which is done in another class. I do not know how to get the same socket that I created in the first class to be used in the second class. If i try and use the same socket, it will give me an error saying that it is a undeclared identifier. Thanks for your help. I know it is probably a simple question, but I am a newbie with program. (Trying to change my career and learn something new)
-
yes that is what i want to do. Only thing is that I create the socket in one class and want to format a message before I send it, which is done in another class. I do not know how to get the same socket that I created in the first class to be used in the second class. If i try and use the same socket, it will give me an error saying that it is a undeclared identifier. Thanks for your help. I know it is probably a simple question, but I am a newbie with program. (Trying to change my career and learn something new)
I presume that you are declaring an instance of the "formatting" class inside the class with the "working" socket??? If you are just add a socket variable to the formatting class and overload the constructor of the formatting class so that when you are creating the formatting class object just do somerhign like this:
MyFormatClass mfc = new MyFormatClass(socket);
Or else you could make the socket variable in the format class public and just set it like:MyFormatClass mfc; mfc.socketvar = this.socket;
But without knowing more about your code and the way your classes work/interact I can't give a definite answer. Regards, Brian Dela :-) http://www.briandela.com[^] -
I presume that you are declaring an instance of the "formatting" class inside the class with the "working" socket??? If you are just add a socket variable to the formatting class and overload the constructor of the formatting class so that when you are creating the formatting class object just do somerhign like this:
MyFormatClass mfc = new MyFormatClass(socket);
Or else you could make the socket variable in the format class public and just set it like:MyFormatClass mfc; mfc.socketvar = this.socket;
But without knowing more about your code and the way your classes work/interact I can't give a definite answer. Regards, Brian Dela :-) http://www.briandela.com[^]Thanks for the help Brian. I am really new to programming, and do not understand how to do what you are telling me. How would I declare an instance of the "formatting" class inside the class with the "working" socket? What other information do you need to know about my program? Many thanks in advance.
-
Thanks for the help Brian. I am really new to programming, and do not understand how to do what you are telling me. How would I declare an instance of the "formatting" class inside the class with the "working" socket? What other information do you need to know about my program? Many thanks in advance.
You said you have a class that formats the string, yeah? ... Unless it is a static function within the class that you are using (i.e. you would be doing something like
MyFormatClass::FormatString(string);
. Otherwise you have to do something like:MyFormatClass mfc;
orMyFormatClass* mfc = new MyFormatClass()
Are you doing anything like this??? If you want, email me on the code. Regards, Brian Dela :-) http://www.briandela.com[^]