Send and recieve data in same code

I am writing a code using ethercard library which sends a post request in setup by calling sendData() and recieves get requests in loop() function but the issue is i am able to do only one task (either send post request or recieve get request) one of them fails(the first called only works).How do i close tcp connection socket after use.

#include <EtherCard.h>

static byte mymac[] = { 0x74,0x69,0x69,0x2D,0x30,0x31 };

byte Ethernet::buffer[700];
static uint32_t timer;

int fPin = 10;
int bPin = 9;

char website[]  = "";

void sendData(){

	int count = 0;
	while(count < 2){


		if (millis() > timer) {

			timer = millis() + 5000;
			Serial.print("<<< REQ ");

char a1[10],a2[10],a3[10],a4[10],ipSend[20];

char b1[10],b2[10],b3[10],b4[10],b5[10],b6[10],macSend[25];

			Stash stash;
			byte sd = stash.create();
			Stash::prepare(PSTR("POST http://$F:8080/Connect/Arduino_data HTTP/1.1" "\r\n"
						"Host: $F:8080" "\r\n"
						"Content-Length: $D" "\r\n"
					website, website, stash.size(), sd);




void setup () {

  pinMode(fPin, OUTPUT);
  pinMode(bPin, OUTPUT);


	if (ether.begin(sizeof Ethernet::buffer, mymac,8) == 0) 
		Serial.println("Failed to access Ethernet controller");
	if (!ether.dhcpSetup())
		Serial.println("DHCP failed");

	ether.printIp("IP:  ", ether.myip);
	ether.printIp("GW:  ", ether.gwip);  
	ether.printIp("DNS: ", ether.dnsip);  

	ether.parseIp(ether.hisip, website);

	ether.hisport = 8080;

	ether.printIp("SRV: ", ether.hisip);

	sendData();        // for post request


void loop () {      //getting get requests

     word len = ether.packetReceive();
     word pos = ether.packetLoop(len);
     if (strstr((char *)Ethernet::buffer + pos, "GET /?PIN9=ON") != 0) {
     Serial.println("Received ON command");
     digitalWrite(bPin, HIGH);
     }else if (strstr((char *)Ethernet::buffer + pos, "GET /?PIN9=OFF") != 0) {
     Serial.println("Received OFF command");
     digitalWrite(bPin, LOW);
     }else if (strstr((char *)Ethernet::buffer + pos, "GET /?PIN10=ON") != 0) {
     Serial.println("Received ON command");
     digitalWrite(fPin, HIGH);
     }else if (strstr((char *)Ethernet::buffer + pos, "GET /?PIN10=OFF") != 0) {
     Serial.println("Received OFF command");
     digitalWrite(fPin, LOW);


I do not know coding much but if I would be there in your place I would use two atmega chips.

Without reading your code, I'd suspect that the problem is that you are not dealing with the http Content-Length header (or the lack thereof). Basically, you need to close the socket after each complete request/reply sequence. There are better ways to do it, but closing the socket is simplest.

I don't think it is the content-length header issue. I think i should close post request connection when starting get request receiving loop but i don't know how to do it.
So how do i close a tcp socket.
If i want my get request receiving to work i should comment out these three lines if any one is missing i won't get any request.
What should i do now to make both post and get work.

  ether.parseIp(ether.hisip, website);

  ether.hisport = 8080;