Click here to Skip to main content
15,907,329 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Problems writing to a file Pin
nbugalia12-Sep-07 23:37
nbugalia12-Sep-07 23:37 
GeneralRe: Problems writing to a file Pin
TheInfernalCrow12-Sep-07 23:45
TheInfernalCrow12-Sep-07 23:45 
AnswerRe: Problems writing to a file Pin
Nishad S13-Sep-07 0:23
Nishad S13-Sep-07 0:23 
QuestionRe: Problems writing to a file Pin
David Crow13-Sep-07 3:08
David Crow13-Sep-07 3:08 
QuestionHi I want to know how to distinguish two mouse signal. Pin
Charles of Korea12-Sep-07 16:40
Charles of Korea12-Sep-07 16:40 
AnswerRe: Hi I want to know how to distinguish two mouse signal. Pin
Sreedhar DV12-Sep-07 19:25
Sreedhar DV12-Sep-07 19:25 
GeneralRe: Hi I want to know how to distinguish two mouse signal. Pin
Roger Broomfield12-Sep-07 21:29
Roger Broomfield12-Sep-07 21:29 
QuestionVery Basic socket programming, Winsock! Newb help.. Pin
Beaon12-Sep-07 7:55
Beaon12-Sep-07 7:55 
Howdy guys,

I joined the forums several days after spending several more days exploring through all the wonderful articles posted here. I had started to teach myself c++ just about 2 months ago. Things go well at times and things go slow, I am sure you can relate to how it was starting how in the programming world.

Right now I have been trying to teach myself how to get a simple connection between two computers. My original plan was to build a basic chat client that acts as a server/client for a peer to peer type of connection. After some problems I have decided to make a very simple console server that listens on a port and prints a string that it receives.

My server listens in a port and it appears I can even make my client have an "ESTABLISHED" connection with my server. However when I send() and recv() data, nothing happends. Or it locks up.

I am concerned that I am not using the right sockets for the right job. What I guess I want is a very general clarification of what each socket will do. I have read through 4 different tutorials here and most have been extremely helpful, however due to my own incompitance I keep getting it wrong!

Right now the way I understand it.

The serverside will have two sockets.

a ListeningSocket
a ClientSocket

WIth the listeningsocket I create the socket.
ListeningSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

Bind the socket to a port and address
addr.sin_addr.s_addr = can be "INADDR_ANY" because its the server and is not targeted to connect at anything,
I bind port 8888, set the IP family type then run the BIND command

bind( ListeningSocket, (const sockaddr *)&addr, sizeof( SOCKADDR_IN ) );

using my SOCKADDR_IN struct to pass information to bind and what not

Then I listen

listen(ListeningSocket,10);

Now here I get somewhat confused

What socket does the accepting?
Right now I have setup the ClientSocket to accept the ListeningSocket

ClientSocket = accept(ListeningSocket, (sockaddr*)&addr, &len);

Is this backwards? Should I have it the otherway around with the ListeningSocket as the lhand value and accept ClientSocket? Many tutorials are pretty vague on this.


Then on the actual client side, I simply create one socket and attempt to connect to the server.

What I have now has appeared to give me a connection according to NETSTAT, however when I send() data nothing happends.

Perhaps my recv loop is setup incorrectly.

Any one have any advice? I hope my question was not to entirely vague, or another good tutorial I could follow along through. The more basic the tutorial the better!

Any help is truely appreciated!

Cliff
AnswerRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery12-Sep-07 8:06
Mark Salsbery12-Sep-07 8:06 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon13-Sep-07 6:03
Beaon13-Sep-07 6:03 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery13-Sep-07 6:15
Mark Salsbery13-Sep-07 6:15 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon13-Sep-07 6:59
Beaon13-Sep-07 6:59 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery13-Sep-07 7:04
Mark Salsbery13-Sep-07 7:04 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon14-Sep-07 3:43
Beaon14-Sep-07 3:43 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery14-Sep-07 6:04
Mark Salsbery14-Sep-07 6:04 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon14-Sep-07 6:20
Beaon14-Sep-07 6:20 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon14-Sep-07 8:22
Beaon14-Sep-07 8:22 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery14-Sep-07 12:39
Mark Salsbery14-Sep-07 12:39 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon17-Sep-07 5:49
Beaon17-Sep-07 5:49 
AnswerRe: Very Basic socket programming, Winsock! Newb help.. Pin
Beaon17-Sep-07 9:21
Beaon17-Sep-07 9:21 
GeneralRe: Very Basic socket programming, Winsock! Newb help.. Pin
Mark Salsbery17-Sep-07 9:43
Mark Salsbery17-Sep-07 9:43 
QuestionDisplaying text in non-english language on console [modified] Pin
ComplexLifeForm12-Sep-07 7:02
ComplexLifeForm12-Sep-07 7:02 
AnswerRe: Displaying text in non-english language on console Pin
Matthew Faithfull12-Sep-07 8:21
Matthew Faithfull12-Sep-07 8:21 
QuestionExiting process Pin
koumodaki12-Sep-07 6:16
koumodaki12-Sep-07 6:16 
AnswerRe: Exiting process Pin
Hamid_RT12-Sep-07 6:44
Hamid_RT12-Sep-07 6:44 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.