Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. help with a TCP Program that sends messages

help with a TCP Program that sends messages

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadminhelp
8 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jay Hova
    wrote on last edited by
    #1

    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.

    A 1 Reply Last reply
    0
    • J Jay Hova

      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.

      A Offline
      A Offline
      Alexander M
      wrote on last edited by
      #2

      read Nishant S's articles here: http://www.codeproject.com/internet/[^] Don't try it, just do it! ;-)

      J 1 Reply Last reply
      0
      • A Alexander M

        read Nishant S's articles here: http://www.codeproject.com/internet/[^] Don't try it, just do it! ;-)

        J Offline
        J Offline
        Jay Hova
        wrote on last edited by
        #3

        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.

        A 1 Reply Last reply
        0
        • J Jay Hova

          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.

          A Offline
          A Offline
          Alexander M
          wrote on last edited by
          #4

          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! ;-)

          J 1 Reply Last reply
          0
          • A Alexander M

            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! ;-)

            J Offline
            J Offline
            Jay Hova
            wrote on last edited by
            #5

            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)

            B 1 Reply Last reply
            0
            • J Jay Hova

              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)

              B Offline
              B Offline
              Brian Delahunty
              wrote on last edited by
              #6

              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[^]

              J 1 Reply Last reply
              0
              • B Brian Delahunty

                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[^]

                J Offline
                J Offline
                Jay Hova
                wrote on last edited by
                #7

                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.

                B 1 Reply Last reply
                0
                • J Jay Hova

                  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.

                  B Offline
                  B Offline
                  Brian Delahunty
                  wrote on last edited by
                  #8

                  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; or MyFormatClass* mfc = new MyFormatClass() Are you doing anything like this??? If you want, email me on the code. Regards, Brian Dela :-) http://www.briandela.com[^]

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups