Linux socket programming

Status
Not open for further replies.

gary36

Full Member level 4
Joined
Mar 31, 2018
Messages
208
Helped
0
Reputation
0
Reaction score
0
Trophy points
16
Activity points
1,806
Hi

I am new to socket programming in linux. I was referring to this site https://www.thegeekstuff.com/2011/12/c-socket-programming/?utm_source=feedburner . I took the example of server code and executed it.

Issues

1. The example program closes the socket at end of this routine. Therefore I have to establish connections everytime from client. How should the code be modified to make server always live (without closing unless client disconnects)?

2. I also faced issues with byte transmission. Data in the range 0-9 is received in client perfectly, but the data greater than 9 is received wrongly. For example 10 is received as 1 and a 0 separately. Any ways to resolve this?
 

You need to provide more information. The given program must close socket after sending info to client. I guess that you need to define protocol first (what is client going to send to server, and what server should send as a response). Look at this example on how to implement multi threaded server: https://gist.github.com/oleksiiBobko/43d33b3c25c03bcc9b2b
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…