Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9217797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:42:49+00:00 2026-06-18T02:42:49+00:00

I am learning socket program in ubuntu for which I wrote the following program

  • 0

I am learning socket program in ubuntu for which I wrote the following program for server client communication. The program is not opening the ports. I also have some other questions regarding server client communications:

  • When the server accepts the client request, does server starts reading from client the moment it accepts the request?
  • Is the file descriptor returned by u_connect and u_accept() same? (I couldn’t find it out because my ports are not opening)
  • Can I use a random number as port since I am testing server client talk on the same computer?

I am using a wrapper library which contains the OS functions for socket programming.

Here is the code:

Server.c

int main()
{
  char client[50];
  char buf[1024];
  u_port_t portnumber;
  portnumber = 4862;
  int fd = u_open(portnumber);
  int communFd = u_accept(fd, client, 50);
  printf("Opened com %d\n\n", communFd);
  fprintf(stderr, "\nComun fd is %d\n\n\n", communFd);
  read(communFd, buf, 1024);
  write(STDOUT_FILENO, buf, 1024);
  fprintf(stderr, "\n\nReading complete\n");
  return 0;
}

Client.c

int main()
{
  u_port_t portnumber;
  portnumber = 4862;
  char client[] = "Alfred";
  char buf[1024];
  int communFd = u_connect(portnumber, client);
  printf("comun is %d\n", communFd);
  read(STDIN_FILENO, buf, 1024);
  write(communFd, buf, 1024);
  return 0;
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:42:50+00:00Added an answer on June 18, 2026 at 2:42 am

    When the server accepts the client request, does server starts reading
    from client the moment it accepts the request?

    Server can read when the data sent by the client (via write()) is received and available into the socket read buffer.

    Is the file descriptor returned by u_connect and u_accept() same? (I
    couldn’t find it out because my ports are not opening)

    No. Not even if server and client sides are running in the same process.

    Can I use a random number as port since I am testing server client
    talk on the same computer?

    You can bind on a port from 0 to 65535.
    The ones from 0 to 1024 are called known ports and are already assigned to specific services by IANA. My suggestion is to use a port number in the range 49152-65535 but noone forbid you to use it a low value.

    If the port is bind by another process it will return an error code. Try with another one

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For learning purposes I am writing a socket based client/server application. I have designed
For learning purposes I am writing a socket based client/server application. I have designed
So I'm learning about socket programming and have wrote a nifty little chat server.
I am learning boost/asio ad wrote 2 programs(client and server) from e-book with minor
I am learning socket programming in c, I wrote this simple program to accept
Recently, I'm learning wxPython. So I wrote a little TCP server program with wxPython.
I'm learning about socket programming in Java. I've seen client/server app examples with some
I am learning objective C.I like to know about client/server(socket) programming for iphone. I
I am learning currently about client server communication using Java through sockets. First of
I'm learning socket programming and I have the following function: public void OnDataReceived(IAsyncResult asyn)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.